2

I am downloading a zip file which has a very deep nested structure from which I just need to pick a few files. The file structure looks like this:

myfile.zip/
C*_01.zip, ....., C*_xx.zip/

In each C*_xx.zip file:

a*.zip
b*.zip
..../
file1.txt
file2.txt
...
targetfile.txt
...

Please note that on each "C*.zip" I need to pick the target file.

I do not have much experience with shell scripting so I have written a script based on other solutions but it doesn't work. I would appreciate any hint:

wget url | find . -name "myfile.zip" | while ["`find -type f -name 'C*.zip' | wc -l`" -gt 0 ]; do find -type f -name "b.zip" | find -type f -name "targetfile.txt" exec unzip -- '{}' \;; done
2
  • You want to extract targetfile.txt from all C*.zip archives contained in the myfile.zip archive?
    – ingopingo
    Feb 21, 2017 at 18:56
  • @ingopingo yes, exactly
    – nopeva
    Feb 21, 2017 at 20:18

1 Answer 1

1

Create a script file like fetchtarget.sh and start it with the URL as first argument.

#!/bin/sh

dir=$(mktemp -d)
cd $dir || exit

wget $1

# deep unzip loop
while true; do
   find -iname '*.zip' > zipindex
   test -s zipindex || break
   for zip in $(cat zipindex); do unzip -o $zip && rm $zip; done
done

# purge and show result
find $dir -name targetfile.txt -print -or -type f -exec rm {} \; 
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .