2

I need to extract more than 2k files from 1000 folders..the problem is, each folder has a zipped folder inside and inside this folder, there is another folder called "fileholder" which contains some temp.processed filetype that I need to get. Is there any way to search for all these files and copy them to another location? or do I have to extract all of the zip files?

I have ran:

 find -type f -iname \*.PROCESSED

but that does not search inside the zipped files. Can someone point me to the right direction?

1 Answers1

2

I would do it in two find calls:

  • One to find all zip files and then process them
  • Another to deal with the regular files

This is a little cumbersome, the complicated part is the awk call. It processes the output of unzip -l which is not very script friendly. It searches for lines starting with numbers (to get rid of the headers), gets rid of empty lines, and finally matches the .process in a case insensitive manner.

FINDDIR="."
for f in `find "$FINDDIR" -type f -iname '*.zip'`; do
  dir=`dirname "$f"`
  for p in `unzip -l sth.zip | awk '{if (match($1, /^[0-9]+$/) && $1 > 0 && match(tolower($4), /\.processed$/)) print $4}'`; do
    echo "$dir/$p"
done
find "$FINDDIR" -type f -iname '*.processed'

This cannot deal with recursive zips, i.e. if a zip archive is inside another zip archive.

grochmal
  • 8,657