advanced grep question

Steven J Lamb redhattedsheep at adiis.net
Thu Feb 2 15:39:43 UTC 2006


what I am looking for is information on how to use grep in the following 
way. I want to do essentially this

grep (string1|string2|string3) filename

I would use this to search filename for either string1, string2 or string 3 
instances

I realize I could do the following but would like to use it as one grep 
statement as I believe it should be more efficient.

>tmp;
grep string1 filename >>tmp;
grep string2 filename >>tmp;
grep string3 filename >>tmp

as this would be defined in a normal regular expression. grep claims to be 
able to use this functionality as best I can tell ... it is documented in 
the man page and it says

 Two  regular  expressions  may be joined by the infix operator |; the 
resulting regular expression matches
       any string matching either subexpression.

I have not been able to find an example of this anywhere and have tried 
several forms of the syntax but no luck. my command interpreter keeps trying 
to use the pipe instead of letting grep have it.

any one have any thoughts

thanks


Steven Lamb 




More information about the users mailing list