GUNZIP / Extract file "portion by portion" GUNZIP / Extract file "portion by portion" shell shell

GUNZIP / Extract file "portion by portion"


If you're doing this with (Unix/Linux) shell tools, you can use gunzip -c to uncompress to stdout, then use dd with the skip and count options to copy only one chunk.

For example:

gunzip -c input.gz | dd bs=10485760 skip=0 count=1 >output

then skip=1, skip=2, etc.


Unfortunately I don't know of an existing Unix command that does exactly what you need. You could do it easily with a little program in any language, e.g. in Python, cutter.py (any language would do just as well, of course):

import systry:  size = int(sys.argv[1])  N = int(sys.argv[2])except (IndexError, ValueError):  print>>sys.stderr, "Use: %s size N" % sys.argv[0]  sys.exit(2)sys.stdin.seek((N-1) * size)sys.stdout.write(sys.stdin.read(size))

Now gunzip <huge.gz | python cutter.py 1000000 5 > fifthone will put in file fifthone exactly a million bytes, skipping the first 4 million bytes in the uncompressed stream.