我想找到所有包含两行的文件:abc
和def
。例如,
xxx
111abc
yyy
222def333
此文件应被捕获,grep
因为它包含abc
和def
。
我应该怎么办?我已经尝试过了,grep -rE 'abc.*def' /dir/
但是没有用。
在GNU系统上,如果匹配的相对顺序无关紧要,则可以使用两种模式进行工作:
grep -rlZ abc /dir/ | xargs -r0 grep -l def
如果您有两个以上的模式,则可以将其链接起来:
grep -rlZ abc /dir/ | xargs -r0 grep -lZ def | xargs -r0 grep -l xxx
或使用find
:
find /dir/ -type f -exec grep -q abc {} \; -exec grep -q def {} \; -print
这不是很有效,是另一种grep
可能比该任务更好的工具。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句