Open mipuha opened 3 years ago
Better yet, just receive file args on STDIN, then you could pipe it all together:
ag --py -l -Q keyword1 | ag --py -l -Q keyword2 | ag --py -l -Q keywordN
Still better, allow the above functionality without piping:
ag --py -l -Q -e keyword1 -e keyword2 -e keywordN
using random "-e" option for this.
Agreed that an option to read a file list from STDIN would be really useful. It would mean that you can pipe multiple ag's to achieve complex searches.
E.g. files that contain foo but not bar, or files that contain foo and bar.
BTW, ack has this:
-x Read the list of files to search from STDIN.
Agreed that an option to read a file list from STDIN would be really useful. It would mean that you can pipe multiple ag's to achieve complex searches.
I'm not connecting the dots on this. Can you use an example of what that command line would look like to pull this off?
Suppose I want the list of all files which contain 'foo' but NOT 'bar'. With ack's -x option, I can do:
ack -l foo | ack -x -L bar
which breaks down as:
ack -l foo
-- find all files containing foo, output just the list of filenamesack -x -L bar
-- within the piped list of files, find all files which don't contain barYou can chain as much as you like to achieve more complex conditions.
Some things you could do with a regex with lookaheads, but that's assuming the relative order of the two strings is always the same in all files, and also the regexes would get pretty nasty pretty quickly. Piping simple conditions together is much simpler to understand.
Here's another example I had today.
In my Drupal site's config folder I have lots of files named wsd_test.test_type.*.yml
. I want to search within the ones that contain the string 'wsd_commons', and I want to see in those what they say after the string 'config'.
The following gets me that:
ag -G wsd_test.test_type wsd_commons -l | ack -x -A5 config
I had to use ack
for the final part for its -x flag. It breaks down as:
ag -G wsd_test.test_type wsd_commons
-- find all files whose filename matches, and which contain 'wsd_commons', listing just the filenames
Usecase in short: among codebase(s) I want to find python files that contain three different keywords.
Some tools have a similar option to read the search space from a separate file. Is this something
ag
could have some day? Is there another way I could achieve this today?