Path: utzoo!attcan!uunet!mcvax!ukc!stl!ist!icdoc!cam-cl! From: rbj@arpa.icst-cmr (Root Boy Jim) Newsgroups: comp.unix.wizards Subject: grep replacement (first match only per file) Message-ID: <8806101955.AA29050@cmr.icst.nbs.gov> Date: 10 Jun 88 19:55:21 GMT Sender: unix-wizards-request@uk.ac.ucl.cs.nss Lines: 31 To: jgreely@edu.ohio-state.cis.dimetrodon Cc: unix-wizards@mil.brl.sem ? 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?