Re: [Nolug] grepping multiple strings

From: Scott Harney <scotth_at_scottharney.com>
Date: Mon, 03 Mar 2003 07:53:00 -0600
Message-ID: <87bs0sd0ar.fsf@zenarcade.local.lan>

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)

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

-- 
Scott Harney<scotth@scottharney.com>
"...and one script to rule them all."
___________________
Nolug mailing list
nolug@nolug.org
Received on 03/03/03

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