本文介绍了查找包含多个字符串的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用命令来递归查找包含某个string1
的文件:
I use a command to recursively find files containing a certain string1
:
find . -type f -exec grep -H string1 {} \;
我需要查找包含多个字符串的文件,因此该命令应返回包含所有字符串的文件.像这样:
I need to find files containing multiple strings, so the command should return those containing all strings. Something like this:
find . -type f -exec grep -H string1 AND string2 {} \;
我找不到办法.字符串可以在文件中的任何位置.甚至只有两个字符串的解决方案也是不错的.
I couldn't find a way. The strings can be anywhere in the files. Even a solution for only two strings would be nice.
推荐答案
您也可以尝试一下;
find . -type f -exec grep -l 'string1' {} \; | xargs grep -l 'string2'
这显示了包含string1和string2的文件名
this shows file names that contain string1 and string2
这篇关于查找包含多个字符串的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!