I have a couple of patterns I would like to ask grep to find in some files. Assume I have a file containing
我有几个模式,我想问grep在一些文件中找到。假设我有一个包含的文件
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一次是我在这里问我自己
1 个解决方案
#1
0
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在文件中使用模式(每行作为模式)
#1
0
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在文件中使用模式(每行作为模式)