I have a file, foo.zip which looks something like this:

-- fileA.txt
-- fileB.txt

I can pipe the output of the extracted files like this:

unzip -p foo.zip *.txt | something

My problem is that I want to make sure that the files are in the correct order, e.g. that fileA.txt is extracted and piped before fileB.txt.

Can I do that in some way and still avoid writing the files temporarily to disk?


The order should be the same of zip. So if you can control the zip process, then you can order the file addition as you please and unzip should come out in that order.

If you do not do the zip yourself, then you would have to unzip them to the file system and reorder as there is not an easy way to order them.

If you really want to avoid create temporary files, you can use something like

unzip -l -qq foo.zip | awk '{print $4}' 

to get the content, sort the file names as you like, and then unzip them one by one.


There's a lot of shoulds and coulds. If you want to be sure extract them individually and cat it together.

cat `unzip -p foo.zip fileA.txt` `unzip -p foo.zip fileB.txt` ... | something

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.