18

Does there exist a magical shell piping which would allow easily to grep through bunch of .gz log files without needing to extract them somewhere?

.gz files are Apache logs, result of log rotation. I'd like to quickly check how often certain URIs are accessed in the past.

Mikko Ohtamaa
  • 1,364
  • 3
  • 17
  • 28

5 Answers5

27

The zgrep program is available for Linux (and perhaps some Unix too). This will decompress the files and then grep through them.

user9517
  • 114,104
  • 20
  • 206
  • 289
8

Should you for some reason lack zgrep you can do the same thing with gunzip and a pipe:

gunzip -c <filename.gz> | grep <whatever you want to grep for>
pehrs
  • 8,749
  • 29
  • 46
4

You can just use zgrep to grep through compressed files.

If you need to use a specific grep, you can set the GREP environment variable:

export GREP=/bin/egrep
Cakemox
  • 24,141
  • 6
  • 41
  • 67
3

How about zgrep? Seems to be installed on Mac OS and Ubuntu 11.04.

dkam
  • 149
  • 3
3

I usually use:

zcat filename.gz | less

Lucas Kauffman
  • 16,818
  • 9
  • 57
  • 92
garconcn
  • 2,378
  • 7
  • 33
  • 46