Perl solution (was Re: Quit on match)

Randal Schwartz merlyn at iwarp.intel.com
Thu Dec 21 09:13:30 AEST 1989


In article <428 at sunny.ucdavis.edu>, poage at 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 at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list