the_silver_searcher
the_silver_searcher copied to clipboard
How to search for multiple terms in a file?
I'm looking for a way to use ag
to search for multiple keywords in files. For example, I would like to grep through all files within a folder that have both terms present anywhere in the file (in this case "head" and "qt" from the Homebrew Formula folder).
Is there a clean way to use an and operator as such? I though that there may be other solutions as in other here, however it even appears that these commands (such as awk '/pattern1/ && /pattern2/' *
) only match via and
per line and not the entire file...
It appears that this will do the trick, but perhaps there's a more efficient method:
ag -l pattern1 * | tr '\n' '\0' | xargs -0 ag pattern2