Re: [Nolug] grepping multiple strings

From: Ron Johnson <ron.l.johnson_at_cox.net>
Date: 03 Mar 2003 11:41:22 -0600
Message-Id: <1046713281.11430.7.camel@haggis>

On Mon, 2003-03-03 at 07:53, Scott Harney wrote:
> Ron Johnson <ron.l.johnson@cox.net> writes:
>
> Egrep is your friend.
> 'egrep "this|that" filename ' for an 'or' grouping. You need to
> invoke egrep and you need to use the double quotes to keep the
> shell from interpreting the vertical bar as a pipe.
>
> For 'and' situations, just use stdout and pipes to narrow
> your output results:
> grep this filename | grep that
> This prints out any lines containing 'this' and pipes them into the
> second grep which narrows that list down to lines containing 'that'.
>
> To do 'and' greps in a single command. you need 3rd party tools:
> perl -ne 'print if /this/ && /that/ && /dese/ && /dose/' filenames
> (sed & awk could also be used)

Thanks. I wonder why egrep doesn't have an "and" operator also. That
seems like a big oversight.

> Two O'Reilly books really worth having: Unix Power Tools and Mastering
> Regular Expressions.
>
> > Hi,
> >
> > How do I specify "and" and "or" qualifiers in grep?
> >
> > Here's a theoretical syntax for what I'm talking about:
> > $ grep -n --match=and snafu.txt foo bar
> > $ grep -n --match=or snafu.txt foo bar
> >
> > I've seen it done, but can't find where I wrote it down.
> >
> > Thanks

-- 
+-----------------------------------------------------------+
| Ron Johnson, Jr.     Home: ron.l.johnson@cox.net          |
| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson |
|                                                           |
| The difference between Rock&Roll and Country Music?       |
| Old Rockers still on tour are pathetic, but old Country   |
| signers are still great.                                  |
+-----------------------------------------------------------+
___________________
Nolug mailing list
nolug@nolug.org
Received on 03/03/03

This archive was generated by hypermail 2.2.0 : 12/19/08 EST