简体   繁体   中英

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 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 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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM