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:Peterdadmomand their corresponding replacements are in file C:JohnwifegrandpaExpected 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.txtit works if there is only one line in file B & file C, if there is more than one line, it won't work.
Replace strings in a file based on a list of strings and a list of corresponding replacements
text processing;sed;awk;perl
solution i've created is not very short, but is simple enough to be very readable. unless your task was to do the whole thing with sed... ? #!/usr/bin/bash cp A.txt D.txt x=1 length=$(wc -l B.txt | sed 's/\ .*//g') until [ $x -eq $length ]; do    Bx=$(awk NR==$x B.txt)    Cx=$(awk NR==$x C.txt)    sed -i s/$Bx/$Cx/g D.txt    x=$(($x+1)) done rm -f ./sed*note that this script creates a tonne of junk files if B.txt longer than C.txt and perhaps visa versa (didn't test it that far)