3 ms·
Not exactly what you’re asking for but similar: I wrote a script called aag, based on ag, that lets you find files that contain multiple matches anywhere in the
by HellsMaddy 4y ago
Not exactly what you’re asking for but similar: I wrote a script called aag, based on ag, that lets you find files that contain multiple matches anywhere in the file. It’s a per-file logical AND of multiple ag searches.
https://gist.github.com/b0o/f0759c84af6ef773a37a499fdb1c05af https://gist.github.com/b0o/f0759c84af6ef773a37a499fdb1c05af
Example: you’re trying to find a file that contains the strings “MIT License” (case insensitive), “npm install”, and a match for “react-.*” somewhere in your home directory:
aag ~ ---- -i "mit license" --- "npm install" --- "react-.*"
The excessive dashes are necessary so that it’s possible to pass different options to each separate invocation of ag.
In case it’s not clear why this is useful, normally ag (or grep) searches are linewise. It’s not so easy if you are looking for things that occur on different lines, and possibly in different orders.