grep replacement (first match only per file)
Root Boy Jim
rbj at arpa.icst-cmr
Sat Jun 11 05:55:21 AEST 1988
? From: J Greely <jgreely at dimetrodon.cis.ohio-state.edu>
? In article <1998 at u1100a.UUCP> krohn at u1100a.UUCP (Eric Krohn) writes:
? >To put in a plug for Larry Wall's perl language (Release 2.0 due soon at a
? >comp.sources.unix near you):
? >[suggests the following script for grep-first-only]
? >perl -n -e 'if(/Subject/){print $ARGV,":",$_;close(ARGV);}' * >/dev/null
?
? This works, and is indeed faster. However, it shares one problem with
? all of the others: '*' expansion. As an (uncomfortable) example,
? /usr/spool/news/talk/bizarre has over 2500 articles in it at our site,
? and the shell can't expand that properly (SunOS 3.4, if it matters).
? So, the following perl script accomplishes the same thing, no matter
? how many files need searched:
[replacement solution deleted]
Don't forget about xargs.
? (jgreely at cis.ohio-state.edu; ...!att!cis.ohio-state.edu!jgreely)
? Team Wheaties says: "Just say NO to rexd!"
? /^Newsgroups: .*\,.*\,.*\,/h:j /[Ww]ebber/h:j
? /[Bb]irthright [Pp]arty/j /[Pp]ortal/h:j
(Root Boy) Jim Cottrell <rbj at icst-cmr.arpa>
National Bureau of Standards
Flamer's Hotline: (301) 975-5688
The opinions expressed are solely my own
and do not reflect NBS policy or agreement
My name is in /usr/dict/words. Is yours?
More information about the Comp.unix.wizards
mailing list