我想使用grep和一个stopwords文件来过滤掉另一个文件中的常用英语单词.文件“somefile”每行包含一个单词.
cat somefile | grep -v -f stopwords
这种方法的问题是:它检查某些文件中是否出现停用词中的单词,但我想要相反,即检查某些文件中的单词是否出现在停用词中.
这该怎么做?
例
somefile包含以下内容:
hello o orange
停用词包含以下内容:
o
我想从somefile中过滤掉单词“o”,而不是hello和orange.
解决方法
我想了一下,找到了解决方案……
使用grep的-w开关来匹配整个单词:
grep -v -w -f stopwords somefile