Basic Grep Question

Joe Smith jes at
Wed Mar 14 02:20:41 UTC 2007

Dotan Cohen wrote:
> From Dan's question, it appears that he wants AND behaviour, not OR
> behaviour, from the two greps.

I had to look at it three times as well.

The command line amounts to "not cat and not gray" which is logically 
equivalent to "not (cat or gray)".

For the inverse (cat and gray), I would never have guessed at Marc's 
solution. I just use as many greps as needed.

If the OP's motive was efficiency, you're meowing up the wrong tree it 

$ time grep -P "(?=.*cat)(?=.*red)" /usr/share/dict/words | wc
      80      80    1082

real    0m0.400s
user    0m0.366s
sys     0m0.018s

$ time grep cat /usr/share/dict/words | grep red | wc
      80      80    1082

real    0m0.051s
user    0m0.017s
sys     0m0.019s

(sorry, there are no matches for cat and gray)


More information about the users mailing list