0

I receive a tar.gz file which packages multiple zip files - reproduced below:

$ rm -Rf zipdir; mkdir zipdir; echo foo > zipdir/a.txt; echo bar > zipdir/b.txt; cd zipdir; zip -m a.zip a.txt ; zip -m b.zip b.txt; cd ..; tar -czvf zipdir.tar.gz zipdir

$ tar tzfO zipdir.tar.gz zipdir/ zipdir/a.zip zipdir/b.zip

$ tar xzfO zipdir.tar.gz --no-anchored a.zip | gunzip -c foo $ tar xzfO zipdir.tar.gz --no-anchored b.zip | gunzip -c bar

Extracting with gunzip (or zcat -r) for some reason stops at the first file. Subsequent files are not processed:

$ tar xzfO zipdir.tar.gz | gunzip -c
foo

How to concatenate contents of all zip files piped from STDOUT?

$ tar xzfO zipdir.tar.gz | ?
foo
bar

1 Answers1

2

Using GNU tar:

$ zcat zipdir.tar.gz | tar x --to-command='zcat $TAR_FILENAME'
bar
foo

This won't unpack the original tar.gz and extract the contents of each zip file to stdout. (My order in the tar is the other way around, hence bar before foo.)

Freddy
  • 25,565