Mithrand1r
Mithrand1r

Reputation: 2353

zgrep multiple gz files in directory

I have problem executing zgrep command for looking for word in the directory where I have almost 1000 *.gz files.

I am trying with:

find /var/www/page/logs/ -name "*.gz" -exec zgrep '/index.php' {} \;

result is:

GET : '/index.php'
GET : '/index.php'
GET : '/index.php'

And it works.I get list of occurance of index.php with no file name where it was found. It is kind of useless for me unless i knew in which files (filename) it appears.

How can i fix it?

Upvotes: 10

Views: 30387

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207465

Make grep search in two files, then it will tell you which one it found it in:

find /var/www/page/logs/ -name "*.gz" -exec zgrep '/index.php' {} /dev/null \;

And it won't take long to search in /dev/null.

Here is an example without /dev/null:

zgrep chr your.gz
>chrMCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken
>chrgi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]

and with /dev/null

zgrep chr your.gz /dev/null
your.gz:>chrMCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken
your.gz:>chrgi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]

Upvotes: 4

devnull
devnull

Reputation: 123478

You could supply the -H option to list the filename:

find /var/www/page/logs/ -name "*.gz" -exec zgrep -H '/index.php' {} \;

If you wanted only the list of matching files, use -l:

find /var/www/page/logs/ -name "*.gz" -exec zgrep -l '/index.php' {} \;

Upvotes: 18

Related Questions