Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the files found by one ag search as the domain for a second ag search?

Tags:

ag

Suppose I do ag -l foo. That gets me a list of files.

How can I use ag a second time to search within just those files?

like image 679
joachim Avatar asked Oct 12 '25 10:10

joachim


1 Answers

Assuming you're in the bash shell, you do this:

ag whatever $(ag -l foo)

So to find all the files that match both cat and dog:

ag cat $(ag -l dog)

You could also use xargs:

ag -l dog | xargs ag cat

If you used ack, another greplike tool, you could use the -x option to read the list of input files from stdin:

ack -l dog | ack -x cat
like image 199
Andy Lester Avatar answered Oct 15 '25 03:10

Andy Lester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!