Assuming you have stop words file / tmp / words:
in the
you can create sed from it:
sed 's|^|s/\\<|; s|$|\\>/[CENSORED]/g;|' /tmp/words > /tmp/words.sed
this way you get /tmp/words.sed:
s/\<in\>/[CENSORED]/g; s/\<the\>/[CENSORED]/g;
and then use it to censor any text file:
sed -e -f /tmp/words.sed /input/file/to/filter.txt > /censored/output.txt
Sed requires -e to understand the extended regular expression needed for recognition. Of course, you can change [censored] to any other line or an empty line if you want.
This solution will process many words per line, as well as one word in line files.
MichaΕ Ε rajer
source share