You can script the creation of the sed
script. Assuming a file of word pairs:
$ cat words.dat
apple pecan
banana walnut
cherry almond
and a text file:
$ cat textfile.txt
apple
banana
cherry
I would like an apple pie. Cherry pies are good, too. What about bananas?
Bananas are full of potassium.
You can do:
awk '{print "s/" tolower($1) "/" tolower($2) "/g;s/" toupper(substr($1,1,1)) tolower(substr($1,2)) "/" toupper(substr($2,1,1)) tolower(substr($2,2)) "/g"}' words.dat > sedscript.sed
The sed
script:
$ cat sedscript.sed
s/apple/pecan/g;s/Apple/Pecan/g
s/banana/walnut/g;s/Banana/Walnut/g
s/cherry/almond/g;s/Cherry/Almond/g
and then:
$ sed -f sedscript.sed textfile.txt
pecan
walnut
almond
I would like an pecan pie. Almond pies are good, too. What about walnuts?
Walnuts are full of potassium.
s/abc/def/g
s/Abc/Def/g
It is not a problem for one word, but I have over 1000 of them...