Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!mauxci!eci386!ecicrl!clewis From: clewis@ferret.ocunix.on.ca (Chris Lewis) Newsgroups: comp.unix.shell Subject: Re: does a zgrep exist? (zgrep <> zcat | grep) Message-ID: <1366@ecicrl.ocunix.on.ca> Date: 19 Feb 91 18:59:35 GMT References: <1991Feb15.232854.13378@robobar.co.uk> Organization: Elegant Communications Inc., Ottawa, Canada Lines: 32 In article <1991Feb15.232854.13378@robobar.co.uk> ronald@robobar.co.uk (Ronald S H Khoo) writes: >brister@decwrl.dec.com (James Brister) writes: > >> It would be nice to grep through compressed files. Sure, you can do zcat | >> grep regexp, but then you loose the ability of grep to tell you the >> filename and/or linenumber of a match. >Well, if you have it, zcat | grep regexp /dev/stdin would do what you wanted. >If you can't hack a /dev/stdin driver into your kernel, then as an alternative >you could modify grep to understand "-" as a filename. Another approach is some variation (as in, this is untested, but the algorithm's okay) on: pat=$1 shift for i do case $i in *.Z) zcat $i | grep -n "$pat" ;; *) grep -n "$pat" $i ;; esac | sed -e 's/^/'$i': /' done -- Chris Lewis, Phone: (613) 832-0541, Internet: clewis@ferret.ocunix.on.ca UUCP: uunet!mitel!cunews!latour!ecicrl!clewis; Ferret Mailing List: (ferret-request@eci386); Psroff (not Adobe Transcript) enquiries: psroff-request@eci386, current patchlevel is *7*.