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

StackOverflow https://stackoverflow.com/questions/15043804

  •  11-03-2022
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

ack-grep -l Peter | xargs ack-grep -l James | xargs ack-grep 'Peter|James'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top