Linux内核源码中有很多文件config/*
我想找到一个和我的板子类似的文件。
所以我尝试:
egrep -l -e key1 -e key2 config/*
Sample config/file1:
This is key1
This is key2
Sample config/file2:
This is key1
Sample config/file3:
This is key2
但结果是 key1
或 key2
文件列表。
我想要包含 key1
和 key2
的结果
或者有其他简单的unix shell可以生成结果吗?
在前面的示例中,我只想列出“file1”。
最佳答案
我的建议:
( grep -l key1 config/* ; grep -l key2 config/* ) |sort |uniq -c |grep '^ *2\>' |awk '{print $2}'
第一个 grep
打印包含 key1
的所有文件,第二个 grep
打印包含 key2
的所有文件,
然后sort
、uniq
和第三个grep
过滤器列出两次的文件,即包含两个键。
关于grep - 如何通过grep查找不同行中包含两个关键字的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13642549/