I've found a way to replace words in a file inputfile.txt
with matching words from substitutes.txt
in bash with sed
.
For example:
File substitutes.txt
contains word pairs to be replaced:
Good=ok
sat=cat
I use the following code:
sed -e 's/^/s%/' -e 's/=/%/' -e 's/$/%g/' substitutes.txt |
sed -f - inputfile.txt >outputfile.txt
This replacement ist a bit aggressive and replaces Goodyear
with okyear
or saturday
with caturday
, but it should leave those words alone.
Here's the question:
How can word boundaries (\b
) be implemented into this replacement, so that only words (and not parts of words) will be replaced?