Xref: utzoo comp.unix.wizards:8972 comp.unix.questions:7323 Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!rochester!cornell!uw-beaver!tektronix!reed!tessi!joey From: joey@tessi.UUCP (Joe Pruett) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Message-ID: <470@q7.tessi.UUCP> Date: 30 May 88 18:37:09 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> Organization: TSSI, Beaverton, Oregon Lines: 14 > >> 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 This works, but is quite slow if the input to grep is large. A hack I've made to egrep is a switch of the form -. This causes only the first matches to be printed, and then the next file is searched. This is great for: egrep -1 ^Subject * in a news directory to get a list of Subject lines.