Xref: utzoo comp.unix.wizards:9167 comp.unix.questions:7466 Path: utzoo!dciem!nrcaer!cognos!brianc From: brianc@cognos.uucp (Brian Campbell) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Message-ID: <3127@cognos.UUCP> Date: 7 Jun 88 14:17:57 GMT Article-I.D.: cognos.3127 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> <7 Jun 88 14:17:57 GMT Reply-To: brianc@cognos.UUCP (Brian Campbell) Organization: Cognos Incorporated, Ottawa, Canada Lines: 23 In article <4524@vdsvax.steinmetz.ge.com> Bruce G. Barnett writes: > There have been times when I wanted a grep that would print out the > first occurrence and then stop. In article <1036@cfa.cfa.harvard.EDU> Bill Wyatt suggests: > grep '(your_pattern_here)' | head -1 In article <4537@vdsvax.steinmetz.ge.com> Bruce G. Barnett replies: > There are times when I want the first occurrence of a pattern without > reading the entire (i.e. HUGE) file. If we're talking about finding subject lines in news articles: head -20 file1 file2 ... | grep ^Subject: > Or there are times when I want the first occurrence of a pattern from > hundreds of files, but I don't want to see the pattern more than once. In this case, the original suggestion seems appropriate: grep pattern file1 file2 ... | head -1 -- Brian Campbell uucp: decvax!utzoo!dciem!nrcaer!cognos!brianc Cognos Incorporated mail: POB 9707, 3755 Riverside Drive, Ottawa, K1G 3Z4 (613) 738-1440 fido: (613) 731-2945 300/1200/2400, sysop@1:163/8