简体   繁体   English

文件中提供了多种模式的grep

[英]grep with multiple patterns supplied in a file

I have a couple of patterns I would like to ask grep to find in some files. 我有几种模式,我想请grep在某些文件中找到。 Assume I have a file containing 假设我有一个包含

pattern1
pattern2
pattern3
pattern4
...
patternx

and instead of editing a grep in front of each pattern,like: 而不是在每个模式之前编辑grep,例如:

grep pattern1 arg
grep pattern2 arg
...
grep patternx arg

I would prefer to feed the whole amount of patterns one time to grep and have grep produce the output. 我宁愿一次将全部模式提供给grep并让grep产生输出。

I could iterate in a sh for loop of course but the question whether it is possible using grep one time is what I'm asking myself here 我当然可以在sh for循环中进行迭代,但是我一次要问自己的问题是是否可以一次使用grep

If I am understanding you correctly, you are looking for this: 如果我正确理解您的意思,那么您正在寻找以下内容:

grep -f yourPatFile /path/files

You can read man page of grep to find out the details of -f option, basically it allows grep to use patterns in a file(each line as pattern) 您可以阅读grep的手册页以了解-f选项的详细信息,基本上它允许grep使用文件中的模式(每行作为模式)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM