Search code examples
linuxshellgrepack

Find files where 2 given words occur in and also show lines where words appear


Suppose I want to find all files in the current directory that have at least one occurence of the name Peter and at least one occurence of the name James.

I can find a list of those files by doing ack-grep -l Peter * | xargs ack-grep -l James as suggested in this thread.

But how can I also show the lines where these words occur? Simply doing ack-grep Peter * | xargs ack-grep James does not return the expected output.


Solution

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