Search code examples
linuxshellgreppipegunzip

Piping GUNZIP to GREP


I'm trying to find all ZIP files in a specific folder, extract them using GUNZIP, and pipe the output to GREP to search within HTML files contained in these ZIP files.

I managed to do so with UNZIP (unzip -p), but unfortunately due to many servers that I will eventually run that search on with SSH loop, that doesn't have ZIP/UNZIP installed, I'm limited to GUNZIP which is installed on these old Linux kernel servers, I guess that by default.

Is there a way to pipe the output of gunzip extraction (of more than 1 file following a find -exec command) to grep, in a way that will allow searching inside these HTML files (not in their file names, but within)?

That's how I've tried to do it so far, without succeess:

find /home/osboxes/project/ZIPs/*.zip -exec gunzip -l {} \;|grep 'pattern'

UNZIP has a -p option that can pipe the output and I get the needed result with it, but it seems that GUNZIP doesn't...

Can you think of a way to help me make it work?

Appreciated


Solution

  • gunzip -c writes the output to standard output. The original file is not affected. zcat also works, it is the same as gunzip -c.