ggreer / the_silver_searcher

A code-searching tool similar to ack, but faster.
http://geoff.greer.fm/ag/
Apache License 2.0
26.08k stars 1.42k forks source link

how can I use ag like "cat test.txt | grep -f reg_file"? #1264

Open felixlyd opened 6 years ago

felixlyd commented 6 years ago

If the file "test.txt" and "reg_file" are huge, I should use grep like "cat test.txt | grep -f reg_file".

But I cannot find a way to use ag like that in the mannual of ag. And obviously, it will takes lots of time if I use ag with a for-loop.

I think I am a careless user,so that I cannot find the correct parameter.Could you do me a favor?Thanks a lot.

aswild commented 5 years ago

unlike grep, ag doesn't support searching multiple regexes at once anyway, so an equivalent of grep's -f option doesn't make much sense.

Instead, join the regexes to search with | characters using a set of tr/sed/awk/perk/python commands of your choice, such as ag "$(tr '\n' '|' <patterns.txt | sed 's/|$//')" tosearch.txt

It ain't the prettiest, but at least there's only one ag invocation.