【发布时间】:2020-06-24 20:02:47
【问题描述】:
我有一个文本文件,其中有很多英文冗余,例如,每行一个
in excess of
in order to
in order for
...
我想搜索另一个文本文档,看看它是否包含这些短语中的任何一个。如果它只需要打印短语,我可以手动完成其余的工作。我可以在命令行上轻松做到这一点吗?
【问题讨论】:
-
当然,您尝试过/搜索过/实验过什么?
我有一个文本文件,其中有很多英文冗余,例如,每行一个
in excess of
in order to
in order for
...
我想搜索另一个文本文档,看看它是否包含这些短语中的任何一个。如果它只需要打印短语,我可以手动完成其余的工作。我可以在命令行上轻松做到这一点吗?
【问题讨论】:
当然 - 试试 grep
grep -F -f phrases.txt doc.txt
phrases.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 phrases.txt doc.txt
in order to
【讨论】: