从文本文件中提取多个字符串 [英] Grep multiple strings from text file
本文介绍了从文本文件中提取多个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,所以我有一个包含多个字符串的文本文件,例如这个 -
Hello123光环123格拉西亚斯谢谢...
我希望 grep 使用这些字符串从目录中的其他文件中查找具有匹配字符串/关键字的行
grepped 文本文件示例 -
123-example-Halo123321-example-Gracias-com-no321-example-match
所以在这种情况下,输出应该是
123-example-Halo123321-example-Gracias-com-no
解决方案
使用 GNU grep:
grep -f file1 file2
<块引用>
-f FILE
:从 FILE 中获取模式,每行一个.
输出:
<前>123-example-Halo123321-example-Gracias-com-noOkay so I have a textfile containing multiple strings, example of this -
Hello123
Halo123
Gracias
Thank you
...
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
解决方案
With GNU grep:
grep -f file1 file2
-f FILE
: Obtain patterns from FILE, one per line.
Output:
123-example-Halo123 321-example-Gracias-com-no
这篇关于从文本文件中提取多个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文