Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gzip

gunzip

zcat

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. 
like image 820
Govind Kailas Avatar asked Nov 16 '11 12:11

Govind Kailas


People also ask

How can I view the contents of a gz file without extracting it?

Just use zcat to see content without extraction. From the manual: zcat is identical to gunzip -c . (On some systems, zcat may be installed as gzcat to preserve the original link to compress .)

Can you split a GZ file?

How to split a gz file (database dump) into smaller files and move to another server and restore the database dump there? You can split a larger file into smaller pieces using the “split” command.

How can I grep in GZ file without unzipping?

Grep gz files without unzipping As we showed earlier, you can use the zgrep command to search through compressed files without having to unzip them first. You can also use the zcat command to display the contents of a gz file and then pipe that output to grep to isolate the lines containing your search string.


2 Answers

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. 
like image 81
sarnold Avatar answered Oct 22 '22 23:10

sarnold


On some systems (e.g., Mac), you need to use gzcat.

like image 23
Marcelo Cantos Avatar answered Oct 23 '22 01:10

Marcelo Cantos