Searching Multiple Terms
- by nevets1219
I know that grep -E 'termA|termB' files allows me to search multiple files for termA OR termB. What I would like to do instead is search for termA AND termB. They do not have to be on the same line as long as the two terms exists within the same file. Essentially a "search within result" feature.
I know I can pipe the results of one grep into another but that seems slow when going over many files.
grep -l "termA" * | xargs grep -l "termB" | xargs grep -E -H -n --color "termA|termB"
Hopefully the above isn't the only way to do this.
It would be extra nice if this could work on Windows (have cygwin) and Linux. I don't mind installing a tool to perform this task.