Xref: utzoo comp.unix.wizards:9348 comp.unix.questions:7584 Path: utzoo!attcan!uunet!husc6!mailrus!tut.cis.ohio-state.edu!mandrill!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon S. Allbery) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Message-ID: <7973@ncoast.UUCP> Date: 13 Jun 88 21:51:49 GMT References: <7882@alice.UUCP> <5630@umn-cs.cs.umn.edu> <6866@elroy.Jpl.Nasa.Gov> <4524@vdsvax.steinmetz.ge.com> <1036@cfa.cfa.harvard.EDU> <4537@vdsvax.steinmetz.ge.com> <5007@sdcsvax.UCSD.EDU> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 33 As quoted from <5007@sdcsvax.UCSD.EDU> by hutch@net1.ucsd.edu (Jim Hutchison): +--------------- | 4537@vdsvax.steinmetz.ge.com, barnett@vdsvax.steinmetz.ge.com (Bruce G. Barnett) | >In <1036@cfa.cfa.harvard.EDU> wyatt@cfa.harvard.EDU (Bill Wyatt) writes: | >|> 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 | > | >There are times when I want the first occurrence of a pattern without | >reading the entire (i.e. HUGE) file. | | I realize this is dependent on the way in which processes sharing a | pipe act, but this is a point worth considering before we get yet | another annoying burst of "cat -v" type programs. | | grep pattern file1 ... fileN | head -1 | | This should send grep a SIGPIPE as soon as the first line of output | trickles through the pipe. This would result in relatively little | of the file actually being read under most Unix implementations. +--------------- Not true. The SIGPIPE is sent when "grep" writes the second line, *not* when "head" exits! If there *is* only one line containing the pattern, grep will happily read all of the (possibly large) files without getting SIGPIPE. This is not pleasant, even if it's only one large file -- say a comp.sources.unix posting which you're grepping for a Subject: line. -- Brandon S. Allbery | "Given its constituency, the only uunet!marque,sun!mandrill}!ncoast!allbery | thing I expect to be "open" about Delphi: ALLBERY MCI Mail: BALLBERY | [the Open Software Foundation] is comp.sources.misc: ncoast!sources-misc | its mouth." --John Gilmore