0

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

foo.zip
-- 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?

Grav
  • 115
  • 4

2 Answers2

2

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
Chris S
  • 77,337
  • 11
  • 120
  • 212
1

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.

johnshen64
  • 5,747
  • 23
  • 17