new grep

Mike "Ford" Ditto ford at elgar.UUCP
Fri Jun 24 16:34:47 AEST 1988


In article <16237 at brl-adm.ARPA>, williams at 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 <rbj at icst-cmr.arpa>
> 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 at kenobi.cts.com
This was a Pizza Hut,			...!sdcsvax!crash!kenobi!ford
now it's all covered with daisies." -- Talking Heads



More information about the Comp.unix.wizards mailing list