Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!apple!oliveb!orc!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Perl solution (was Re: Quit on match) Keywords: pipeline, grep | cat Message-ID: <5373@omepd.UUCP> Date: 20 Dec 89 22:13:30 GMT References: <10064@saturn.ucsc.edu> <1989Dec16.133416.3855@virtech.uucp> <428@sunny.ucdavis.edu> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: na Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 25 In-reply-to: poage@sunny.ucdavis.edu (Tom Poage) In article <428@sunny.ucdavis.edu>, poage@sunny (Tom Poage) writes: | Alternatively, try | | sed -n '/pattern/{ | p | q | }' filename | | The matching line is printed immediately since output is | flushed on close. Tom. In Perl, to print only the first line of each file that matches a pattern, try: perl -ne 'print, close(ARGV) if /pattern/;' file1 file2 file3... This differs from the sed thing above in that sed would *completely* quit, where this just goes to the next file. Just another Perl hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/