The gzip
compression format supports decompressing a file that has been concatenated from several smaller compressed files (the decompressed file will then contain the concatenated decompressed data), but it doesn't support decompressing a cut up compressed file.
Assuming you would want to end up with a "slice" of the decompressed data, you may work around this by feeding the decompressed data into dd
several times, each time selecting a different slice of the decompressed data to save to a file and discarding the rest.
Here I'm using a tiny example text file. I'm repeatedly decompressing it (which will take a bit of time for large files), and each time I pick a 8 byte slice out of the decompressed data. You would do the same, but use a much larger value for bs
("block size").
$ cat file
hello
world
1
2
3
ABC
$ gzip -f file # using -f to force compression here, since the example is so small
$ gunzip -c file.gz | dd skip=0 bs=8 count=1 of=fragment
1+0 records in
1+0 records out
8 bytes transferred in 0.007 secs (1063 bytes/sec)
$ cat fragment
hello
wo
$ gunzip -c file.gz | dd skip=1 bs=8 count=1 of=fragment
1+0 records in
1+0 records out
8 bytes transferred in 0.000 secs (19560 bytes/sec)
$ cat fragment
rld
1
2
(etc.)
Use a bs
setting that is about a tenth of the uncompressed file size, and in each iteration increase skip
from 0 by one.
UPDATE: The user wanted to count the number of lines in the uncompressed data (see comments attached to the question). This is easily accomplished without having to store any part of the uncompressed data to disk:
$ gunzip -c file.gz | wc -l
gunzip -c
will decompress the file and write the uncompressed data to standard output. The wc
utility with the -l
flag will read from this stream and count the number of lines read.
gzip
. – Stephen Kitt Apr 16 '17 at 14:23gunzip -c file.gz | wc -l
would count the number of lines in the decompressed file. – Kusalananda Apr 16 '17 at 16:10grep
the decompressed data with eitherzgrep
directly, or withgunzip -c file.gz | grep ...
, or pass it throughawk
or any other filter depending on what it is you want to do. – Kusalananda Apr 16 '17 at 17:24