Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GUNZIP / Extract file "portion by portion"

I'm on a shared server with restricted disk space and i've got a gz file that super expands into a HUGE file, more than what i've got. How can I extract it "portion" by "portion (lets say 10 MB at a time), and process each portion, without extracting the whole thing even temporarily!

No, this is just ONE super huge compressed file, not a set of files please...


Hi David, your solution looks quite elegant, but if i'm readying it right, it seems like every time gunzip extracts from the beginning of the file (and the output of that is thrown away). I'm sure that'll be causing a huge strain on the shared server i'm on (i dont think its "reading ahead" at all) - do you have any insights on how i can make gunzip "skip" the necessary number of blocks?

like image 963
Dave Avatar asked May 07 '10 03:05

Dave


1 Answers

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.

like image 71
David Gelhar Avatar answered Oct 02 '22 12:10

David Gelhar