Searching Multiple Terms
Posted
by nevets1219
on Super User
See other posts from Super User
or by nevets1219
Published on 2010-05-28T18:37:44Z
Indexed on
2010/05/28
18:42 UTC
Read the original article
Hit count: 188
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.
© Super User or respective owner