Grep string in files and list file names that contain the string

Hi,
I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat.
My OS is:
SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise

Do your system has zgrep ??

no, don't have zgrep.

Without that you could use

zcat (in case of .Z files)

Hmmm, not really sure how to use that?

Kind of the same way you'd use cat...

If you don't have gzcat it's simple enough to make one:

for FILE in *.gz ; do gunzip < $FILE ; done | ...

gzcat is OK

gzcat *.gz|grep string

But that do not give me the file names in which the string is found.
I also tried:

gzcat *.gz|grep -l string

But that doesn't work, it gives me an error.
So my question is, is there any way to get the file names using gzcat?

Thanks!

You can either gzcat *.gz to a temp directory, and run grep -l on that, or you need a for loop like

for FN in *.gz; do gzcat "$FN" | grep string && echo "$FN"; done
1 Like

It works!

Thanks to all!!