I want to use grep together with a stopwords-file to filter out common english words from another file. The file "somefile" contains one word per line.
cat somefile | grep -v -f stopwords
The problem with this approach is: It checks whether a word in stopwords occurs in somefile, but I want the opposite, i.e. check if a word in somefile occurs in stopwords.
How to do this?
Example
somefile contains the following:
hello
o
orange
stopwords contains the following:
o
I want to filter out only the word "o" from somefile, not hello and orange.
I thought about it some more, and found a solution...
use the -w
switch of grep
to match whole words:
grep -v -w -f stopwords somefile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With