How to get few lines from a .gz compressed file without uncompressing

Govind Kailas picture Govind Kailas · Nov 16, 2011 · Viewed 93.1k times · Source

How to get the first few lines from a gziped file ? I tried zcat, but its throwing an error

zcat CONN.20111109.0057.gz|head
CONN.20111109.0057.gz.Z: A file or directory in the path name does not exist.

Answer

sarnold picture sarnold · Nov 16, 2011

zcat(1) can be supplied by either compress(1) or by gzip(1). On your system, it appears to be compress(1) -- it is looking for a file with a .Z extension.

Switch to gzip -cd in place of zcat and your command should work fine:

 gzip -cd CONN.20111109.0057.gz | head

Explanation

   -c --stdout --to-stdout
          Write output on standard output; keep original files unchanged.  If there are several input files, the output consists of a sequence of independently compressed members. To obtain better compression, concatenate all input files before compressing
          them.

   -d --decompress --uncompress
          Decompress.