How to search for text within compressed file

I was wondering if there's a way to search within a file that's been compressed. i.e. if file a is inside file a.zip or a.gz, is there a a command that will retrieve the string of data I'm looking for in file a, and list which compressed file it found it in?

Please help!

Thanks.

man gunzip
man grep

gunzip -c file.gz | grep pattern

or...
zcat file.gz | grep foo

1) What if I do not know which file contains the string of text I am looking for?

2) Will this work for only .gz files, or for other compressed files as well, i.e. .zip, etc.?

Thanks!

That's what grep does best. Given some files to grep, it searches for the pattern in those files. So you need not worry about that. It will throw up all searches which are successful. i.e. files which contain the pattern.

vino

this can lead to Binary file (standard input) matches,...

to display strings type

zcat file.gz | strings | grep foo

best regards!

If you have an upto date versoin of gzip installed you probably have zgrep as well which will do the lot for you.

zgrep foo <compressed file list>

zgrep should work similar to zcat and grep.

Hey

You can first Unzip the file and then grep into that and then again zip it.

gzip -d file.Z
grep "str" file
gzip -c file > file.Z
rm file

Thanks !!
:b: