Grep来自文本文件的多个字符串 [英] Grep multiple strings from text file

查看:129
本文介绍了Grep来自文本文件的多个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有一个包含多个字符串的文本文件,例如-

Okay so I have a textfile containing multiple strings, example of this -

Hello123
Halo123
Gracias
Thank you
...

我希望grep使用这些字符串从目录中其他文件中查找具有匹配的字符串/关键字的行

I want grep to use these strings to find lines with matching strings/keywords from other files within a directory

被抓取的文本文件示例-

example of text files being grepped -

123-example-Halo123
321-example-Gracias-com-no
321-example-match

因此在这种情况下,输出应为

so in this instance the output should be

123-example-Halo123
321-example-Gracias-com-no

推荐答案

使用GNU grep:

With GNU grep:

grep -f file1 file2

-f FILE:从FILE中获取模式,每行一个.

-f FILE: Obtain patterns from FILE, one per line.

输出:


123-example-Halo123
321-example-Gracias-com-no

这篇关于Grep来自文本文件的多个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆