Xref: utzoo comp.unix.wizards:9056 comp.unix.questions:7364 Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!mailrus!husc6!cca!mirror!rayssd!raybed2!linus!jjg From: jjg@linus.UUCP (Jeff Glass) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Message-ID: <33326@linus.UUCP> Date: 1 Jun 88 14:44:18 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> <470@q7.tessi.UUCP> Reply-To: jjg@linus.UUCP (Jeff Glass) Organization: The MITRE Corporation, Bedford MA Lines: 22 In article <470@q7.tessi.UUCP> joey@tessi.UUCP (Joe Pruett) writes: > >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. Try: sed -n -e '/pattern/{' -e p -e q -e '}' filename This prints the first occurrence of the pattern and then stops searching the file. The generalizations for printing the first matches and searching files (where n,m > 1) are more awkward (no pun intended) but are possible. /jeff