【问题标题】:How do a search a text file for a list of phrases contained in another text file? [closed]如何在文本文件中搜索另一个文本文件中包含的短语列表? [关闭]
【发布时间】:2020-06-24 20:02:47
【问题描述】:

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

in excess of
in order to
in order for
...

我想搜索另一个文本文档,看看它是否包含这些短语中的任何一个。如果它只需要打印短语,我可以手动完成其余的工作。我可以在命令行上轻松做到这一点吗?

【问题讨论】:

  • 当然,您尝试过/搜索过/实验过什么?

标签: linux bash shell


【解决方案1】:

当然 - 试试 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

【讨论】:

    猜你喜欢
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多