How to get few lines from a .gz compressed file wi

2019-01-30 17:10发布

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.

标签: gzip gunzip zcat
4条回答
Melony?
2楼-- · 2019-01-30 17:37

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
查看更多
叼着烟拽天下
3楼-- · 2019-01-30 17:37

On a mac you need to use the < with zcat:

zcat < CONN.20111109.0057.gz|head

查看更多
Fickle 薄情
4楼-- · 2019-01-30 17:52

If a continuous range of lines needs be, one option might be:

gunzip -c file.gz | sed -n '5,10p;11q' > subFile

where the lines between 5th and 10th lines (both inclusive) of file.gz are extracted into a new subFile. For sed options, refer to the manual.

If every, say, 5th line is required:

gunzip -c file.gz | sed -n '1~5p;6q' > subFile

which extracts the 1st line and jumps over 4 lines and picks the 5th line and so on.

查看更多
三岁会撩人
5楼-- · 2019-01-30 17:57

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

查看更多
登录 后发表回答