Re: [Nolug] grepping multiple strings

From: Andrew S. Johnson <andy_at_asjohnson.com>
Date: Mon, 3 Mar 2003 11:58:45 -0600
Message-Id: <200303031158.46161.andy@asjohnson.com>

On Monday 03 March 2003 11:41 am, Ron Johnson wrote:
> 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.

Actually, you could include a wildcard ".*" in your search string, which means
any number of any characters match. Try this: egrep "this.*that" filenames.
Isn't this AND?

Andy Johnson

___________________
Nolug mailing list
nolug@nolug.org
Received on 03/03/03

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