tags:

views:

79

answers:

3

Hello All,

I would like to display files that contain more than one expression and exclude files that do not have all expressions.

Any ideas?

Thanks!

+2  A: 

egrep -r 'expression1|expression2|expression3' .

Aaron F.
A: 

if you don't have the -r you can just use grep over again on the results grep expression1 * | grep expression 2 | grep expression 3

trent
+3  A: 

Usually I do that sort of thing by running grep multiple times, something like

grep -l 'expression1' * | xargs grep -l 'expression2' | xargs grep -l 'expression3'

and so on. It doesn't seem very efficient, and I wouldn't be surprised if there is a better way, but I don't know it.

David Zaslavsky
With some domain knowledge (in this case "what regexp is least likely to match") and starting with that regexp, this is probably close to the most efficient solution.
Vatine