If you have many more search patterns, you could save them in a file and read the substitutions from there. For example, say these are the contents of
You can then read a list of N replacements and replace them with this:
while read from to; do
sed -i "s/$from/$to/" infile.txt ;
done < replacements.txt
- This assumes your search strings do not contain spaces and any strange characters need to be escaped in
- It will run one
sed per replacement which may take a while if you have many replacement operations.
- It can deal with an arbitrary number of replacements (thousands or millions or whatever) as long as you don't mind that it will take a bit more time.
Another option would be to write the above as a
You can then run the script on your file and it will make all the replacements in one go:
sed -f replace.sed infile.txt