LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Compressed file (https://www.linuxquestions.org/questions/linux-newbie-8/compressed-file-841440/)

dimpu 10-30-2010 04:29 PM

Compressed file
 
Friends,

I want to know if there is anyway I can extract the first few contents of a zipped file and then the next fixed and so on?

For example, suppose I have a zipped file containing 1000000 natural numbers and I want to extract the first thousand numbers and then the next thousand numbers (1001-2000) and so on till I reach the end. Is this possible?

Thanks

estabroo 10-30-2010 05:22 PM

It should be possible, the deflate algorithm either uses a pre-built tree or builds it on the fly as it decodes, so no extra knowledge beyond that is needed to uncompress on the fly. You might not find a utility that'll do that directly but in linux you should be able to stream the output to your programs input doing something like zcat file.zip | your_program

dimpu 10-31-2010 01:03 AM

Thanks you for your response but I don't wan't to feed that to any program instead I want to save the data in independent files, if possible.

The other thing I could do is use something like head -100 (for zipped files probably zcat), to get the first 100 values and feed it to the program and then consider data values from 101-200 and feed it. I am good with either way but don't really know if that's possible.

Thanks

estabroo 10-31-2010 09:04 AM

Code:

zcat nums.zip | perl -e '$start = shift @ARGV; $stop = (shift @ARGV) + $start; while (<>) { $i++; last if $i>=$stop; print if $i >= $start;}' 10 20


All times are GMT -5. The time now is 05:32 PM.