I am trying to replace strings in a file A
:
Hello Peter, how is your dad? where is mom?
where the strings to be replaced are in file B
:
Peter
dad
mom
and their corresponding replacements are in file C
:
John
wife
grandpa
Expected outcome:
Hello John, how is your wife? where is grandpa?
Can I edit file A
, replacing the value in file B
by using the value from the corresponding line in file C
?
What I have done so far:
cat 1.txt | sed -e "s/$(sed 's:/:\\/:g' 2.txt)/$(sed 's:/:\\/:g' 3.txt)/" > 4.txt
it works if there is only one line in file B
& file C
, if there is more than one line, it won't work.
sed
doesn't do multi-line replacements like that... In fact you want to use some sort of dict here which makes your question similar to this one although not as complicated. – don_crissti Mar 20 '16 at 17:29