Path: utzoo!attcan!uunet!seismo!esosun!ucsdhub!jack!elgar!ford
From: ford@elgar.UUCP (Mike "Ford" Ditto)
Newsgroups: comp.unix.wizards
Subject: Re: new grep
Summary: don't forget -s switch
Message-ID: <199@elgar.UUCP>
Date: 24 Jun 88 06:34:47 GMT
References: <16237@brl-adm.ARPA> <4219@mtgzz.att.com>
Reply-To: ford@kenobi.cts.com (Mike "Ford" Ditto)
Organization: Omnicron Data Systems,  Bonita, CA
Lines: 42

In article <16237@brl-adm.ARPA>, williams@nrl-css.arpa writes:
> 	        Al Aho and I are designing a replacement for grep, egrep
> 		and fgrep.  The question is what flags should it support and
> 		what kind of patterns ...
> 	 
> 	I have always thought it would be nice to print only the first match.
> 	        (Root Boy) Jim Cottrell 
> I'll second this.  There have been many times when I simply wanted to
> detect the presence of a pattern in a file, then stop searching.  Combining
> this with the -n option can also be useful.

Everyone's forgetting an important option: "status only".  I have seen
a few greps that had the -s switch, which would cause grep to exit with
an appropriate status as soon as it "knew" what it should be.  This is
the same as the "only-print-first-match" with no output done at all.

So...

	if who | grep tty000 > /dev/null
	then
		echo "port in use"
		exit
	fi

becomes:

	if who | grep -s tty000
	then
		echo "port in use"
		exit
	fi

which is easier to understand and more efficient (since grep can quit
as soon as it sees a match).


					-=] Ford [=-

"Once there were parking lots,		(In Real Life:  Mike Ditto)
now it's a peaceful oasis.		ford@kenobi.cts.com
This was a Pizza Hut,			...!sdcsvax!crash!kenobi!ford
now it's all covered with daisies." -- Talking Heads