Path: utzoo!attcan!uunet!husc6!rutgers!cmcl2!brl-adm!adm!rbj@cmr.icst.nbs.gov From: rbj@cmr.icst.nbs.gov (Root Boy Jim) Newsgroups: comp.unix.wizards Subject: grep replacement (first match only per file) Message-ID: <16148@brl-adm.ARPA> Date: 13 Jun 88 15:43:25 GMT Sender: news@brl-adm.ARPA Lines: 31 ? From: J Greely ? In article <1998@u1100a.UUCP> krohn@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@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 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?