What is a good way to do string replacements in a file using a dictionary with a lot of substituend-substituent pairs? And by a lot, I actually mean about 20 – not much, but many enough so that I want to organize them neatly.
I kind of want to collect all substituend-substituent pairs in a file
dictionary.txt in an easy-to-manage way, since I need to replace a lot of stuff, say like:
"yes" : "no" "stop" : "go, go, go!" "wee-ooo" : "ooooh nooo!" "gooodbye" : "hello" "high" : "low" "why?" : "i don't know"
Now I want to apply these substitutions in some file
Then I want to run
magiccommand --magicflags dictionary.txt novel.txt so that all instances of
novel.txt are replaced by
no (so even
Bayesian would be replaced by
Banoian) and all instances of
novel.txt would be replaced by
hello and so forth.
So far, the strings I need to replace (and replace with) do not have any quotes (neither single nor double) in them. (It would be nice, though, to see a solution working well with strings containing quotes, of course.)
gawk can do such stuff principally, but can they also work with such dictionary files? Seems like
gawk would be the right candidate for
magiccommand, what are the right
magicflags? How do I need to format my