does a zgrep exist? (zgrep <> zcat | grep)
Tom Christiansen
tchrist at convex.COM
Sat Feb 16 05:20:57 AEST 1991
>From the keyboard of brister at decwrl.dec.com (James Brister):
: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. Uncompressing the files before
:greping isn't really wanted, cause you may not have the space on disk.
:
:Does such a thing exist?
You might look to lwall's pipegrep program. It's on page 265 of
the perl book, and available via anon ftp from uunet inside the
compressed tarchive nutshell/perl/perl.tar.Z in ch6/pipegrep.
You say:
$ pipegrep 'some_pattern' cmd files
so you could say:
$ pipegrep 'foo.*bar$' zcat *.Z
It would only zcat one file at a time, and grep through the pipe,
and then prepend the (command and) filename it found it on. Quoting
from the book:
The pipegrep program greps the output of a series of commands. The
difficulty with doing this using the normal grep program is that you
lose track of which file was being processed. This program prints
out the command it was executing at the time, including the filename.
The command, which is a single argument, will be executed once for
each file in the list.
It's pretty quick little program, faster than stock greps, not
quite so fast as GNU grep.
--tom
--
Tom Christiansen tchrist at convex.com convex!tchrist
"All things are possible, but not all expedient." (in life, UNIX, and perl)
More information about the Comp.unix.shell
mailing list