Re: advanced grep question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steven J Lamb wrote:
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

Use egrep:

egrep "(string1|string2|string3)" filename

does exactly this.

--
Joachim Backes <joachim.backes@xxxxxxxxxxxxxx>
Registered Linux user #407492
University of Kaiserslautern,Computer Center [RHRK],
Systems and Operations, High Performance Computing,
D-67653 Kaiserslautern, PO Box 3049, Germany
--------------------------------------------------
Phone: +49-631-205-2438, FAX: +49-631-205-3056
http://hlrwm.rhrk.uni-kl.de/home/staff/backes.html


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux