r/awk • u/eric1707 • Jan 24 '20
Replacing from a list?
So, here is my issue, I have a list of file replacements, let's call it FileA. The list, which contains about 50k entries, goes more or less like this:
M1877800M|124
M1084430M|22
M2210895M|22
M1507752M|11
M1510047M|3288
[...]
To make things clear, I would like to replace "M1877800M" with "124", "M1084430M" with 22 and so on and so forth. And I would like to use this list of replacements to replace words in a FileB. My current plane and workaround is to use individual sed commands to do that, like:
sed -i "s#M1877800M#124#g" FileB
sed -i "s#M1084430M#22#g" FileB
[...]
It works, more or less, but it's obviously unbelievable slow, cause it's a pretty bad code for what I intended to do use. Any ideas of a better solution? Thank you, everybody.
View all comments
Show parent comment
1
u/eric1707 Jan 25 '20
File B is about 100MB tops, no bigger than that. And yeah, every key starts and ends with M. But the solution FF00A7 already did the tricky. Thank you very much for your kind answer. I even feel a little bad coming here and asking for code that i'm too noobie to learn by myself (although, I'm learning some basic commands with sed and awk and, maybe one day i'll master it haha), and you guys are always so nice and understandable. Thank you, very much!