linux - 查找出现 2 个给定单词的文件,并显示出现单词的行

标签 linux shell grep ack

假设我想在当前目录中找到名称至少出现一次 Peter 且名称 James 至少出现一次的所有文件。

我可以通过 ack-grep -l Peter * | 找到这些文件的列表xargs ack-grep -l Jamesthis thread 中所建议.

但是我怎样才能同时显示这些词出现的行呢? 只需执行 ack-grep Peter * | xargs ack-grep James 没有返回预期的输出。

最佳答案

ack-grep -l Peter | xargs ack-grep -l James | xargs ack-grep 'Peter|James'

关于linux - 查找出现 2 个给定单词的文件,并显示出现单词的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15043804/

相关文章:

c++ - Winelib 能否将 DLL 直接链接到 ELF 可执行文件?

shell - 从 shell 脚本中输入

arrays - 获取 Bash 数组中的最后一个元素

grep 不在 while 循环内工作

linux - 外壳 : choosing string between two strings using sed

linux - 显示不带小写字母的输出

database - cassandra 没有在 ubuntu 中运行

java - 改变运行java程序的线程优先级?

c++ - 使用 G++ 动态编译 C++ 代码片段

c++ - Vim [编译和]运行快捷方式