Linux 如何在文本文件中搜索另一个文本文件中包含的短语列表?

Linux 如何在文本文件中搜索另一个文本文件中包含的短语列表?,linux,bash,shell,Linux,Bash,Shell,我有一个英文文本文件,有很多冗余,例如每行一个 in excess of in order to in order for ... 我想搜索另一个文本文档,看看它是否包含这些短语中的任何一个。如果它只需要打印短语,我就可以手动完成其余的工作。我可以在命令行上轻松地执行此操作吗?当然可以-请尝试grep grep-F-F phrases.txt doc.txt 短语.txt in excess of in order to in order for doc.txt use grep -f in

我有一个英文文本文件,有很多冗余,例如每行一个

in excess of
in order to
in order for
...
我想搜索另一个文本文档,看看它是否包含这些短语中的任何一个。如果它只需要打印短语,我就可以手动完成其余的工作。我可以在命令行上轻松地执行此操作吗?

当然可以-请尝试grep

grep-F-F phrases.txt doc.txt 短语.txt

in excess of
in order to
in order for
doc.txt

use grep -f in order to match this line
this line won't be matched
您可以使用grep-o仅打印匹配的短语,而不是整行:

$grep-o-F-F短语.txt doc.txt 为了
当然,你试过/搜索过/试验过什么?