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

Re: advanced grep question



I should have thought of quoting them ... thanks for all of the responses
----- Original Message ----- From: "Robert Locke" <lists ralii com>
To: "For users of Fedora Core releases" <fedora-list redhat com>
Sent: Thursday, February 02, 2006 9:53 AM
Subject: Re: advanced grep question


On Thu, 2006-02-02 at 09:39 -0600, 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


With basic regular expression you need to quote the "|" so it would be
something like this:

grep 'string1\|string2\|string3' file

The alternative would be to get in to extended regular expression with
egrep or grep -E which would look like:

egrep 'string1|string2|string3' file

HTH,

--Rob


--
fedora-list mailing list
fedora-list redhat com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



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