编辑:我把这个搞得太复杂了。这与反向 grep 无关。我仅使用 得到相同的结果grep -x -f stop.txt < in.txt
。如果在停用词文件中who
位于前面whose
,则结果只是who
. 当停用词文件中的顺序相反时,in.txt
会找到 中的两行。我感觉我根本就不懂grep。
我无法让反向 grep 像我期望的那样工作,以便从文件中删除包含停用词的行。停用词的给出顺序会影响结果。
假设我有两个文件。输入文件in.txt
:
who
whose
Run Code Online (Sandbox Code Playgroud)
以及一个包含停用词列表的文件stop.txt
:
who
whose
Run Code Online (Sandbox Code Playgroud)
如果我in.txt
使用反向 grep 搜索对 中的停用词进行“过滤” stop.txt
,我会得到:
$ grep -vx -f stop.txt < in.txt
whose
$
Run Code Online (Sandbox Code Playgroud)
仅当我更改stop.txt
为
whose
who
Run Code Online (Sandbox Code Playgroud)
我得到:
$ grep -vx -f stop.txt < in.txt
$
Run Code Online (Sandbox Code Playgroud)
我不明白为什么带有停用词的文件中的单词顺序很重要。