Script to unzip files and Rename the Output-files

Hi all,
I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to
find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and only copies one file per name to the new location.

I have tried option 0ne

for file in `find $BASEfolder -depth -name "*.zip"`
do
new=$(unzip -l -qq $file | awk '{print $NF}')
#find $Basefolder -type f -name "*.txt"` 

 # Get BSC definition 
 HIERARCHY_3=`cat $new | grep 'SET SYS:SYSDESC' |  awk -F'"' '{ print $4 }'`
 # Get cell definitions
 cCount=`cat $new | grep 'ADD GCELL:CELLID' | wc -l`
 if [ $cCount -gt 4065 ] ; 
 then 
  echo "More cells in BSC than 4065! ($cCount)"  
  exit
 fi

and Option 2

for file in find . -depth -name "*.zip" -exec /usr/bin/unzip -n {} \;
do
find $Basefolder -type f -name "*.txt"` 

 # Get BSC definition 
 HIERARCHY_3=`cat $file | grep 'SET SYS:SYSDESC' |  awk -F'"' '{ print $4 }'`
 # Get cell definitions
 cCount=`cat $new | grep 'ADD GCELL:CELLID' | wc -l`
 if [ $cCount -gt 4065 ] ; 
 then 
  echo "More cells in BSC than 4065! ($cCount)"  
  exit
 fi

they both failed

Or alternatively how can I find a file in Unix and rename it with a rnadom name

hope this might help you :slight_smile:

find . -type f -name "*.zip" > /myhome/ZIP/FILE_LIST
cd /myhome/ZIP/
for I in `cat FILE_LIST`
do 
    cp ${I} ${I//\//__}
    gunzip ${I//\//__}
done

I dont mind renaming them to the creation date. They are text files.

I tried option above Lohith..

for I in `cat FILE_LIST`
do 
cp ${I} ${I//\//__}
gunzip ${I//\//__}

done
but

cp ${I} ${I//\//__}

creates the files with the same name while i want them with new random names.

:confused:

I was trying this but the mv cmd error: cannot access file

#!/usr/bin/ksh
Home=/var/tmp
cd $Home
for zip in `find $Home -depth -name "*.zip"`
do 
file="$(unzip -l -qq "${zip}" | sed 's/.*:[0-9]\+[[:space:]]*//')" 
newname=$(echo "${file}" | sed 's/ /_/g')
mv {$newname} $Home
done

Anyone Kindly.