Xref: utzoo comp.unix.wizards:8979 comp.unix.questions:7325
Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mtunx!holin!glennr
From: glennr@holin.ATT.COM (Glenn Robitaille)
Newsgroups: comp.unix.wizards,comp.unix.questions
Subject: Re: grep replacement
Summary: Sure it does, if you use a for loop
Message-ID: <50@holin.ATT.COM>
Date: 31 May 88 17:21:16 GMT
References: <7882@alice.UUCP> <5630@umn-cs.cs.umn.edu> <6866@elroy.Jpl.Nasa.Gov> <8077@elsie.UUCP>
Organization: AT&T DSG Holmdel NJ USA
Lines: 39

> > > There have been times when I wanted a grep that would print out the
> > > first occurrence and then stop.
> > 
> > grep '(your_pattern_here)' | head -1
> 
> Doesn't cut it for
> 
> 	grep '(your_pattern_here)' firstfile secondfile thirdfile ...

Well, if you have a shell command like

	#
	# save the search patern
	#
	patern=$1
	#
	# remove search patern from $*
	#
	shift
	for i in $*
	do
		#
		# grep for search patern
		#
		line=`grep ${patern} ${i}|head -1`
		#
		# if found, print file name and string
		#
		test -n "$line" && echo "${i}:\t${line}"
	done

It'll work fine.  If you want to use other options, have them in
quotes as part of the first argument.


Glenn Robitaille
AT&T, HO 2J-207
ihnp4!holin!glennr
Phone (201) 949-7811