Greetings,
I have a bash script that parses ZIP files we receive from a client and uncompresses them if a set of criterias is matched. It works well but it is slow. Particularly, the following function:
function getCTLfile() {
for i in ${HDD_LIST_Array[@]}
do
if [[ `echo ${i}|awk -F . '{print $NF}'` == "ctl" ]]
then
echo "${i}"
fi
done
}
This function’s purpose is to get name of the control file contained in a ZIP file. HDD_LIST_Array[@] is obtained thusly for each zip file:
HDD_LIST_Array=(`unzip -l $name | head -n -2|tail -n +4 | sort -r | awk '{print $4}'`)
Again, it works, albeit slowly. Can this function be optimized to run faster? Any advice?
Thanks.
unzip -ltakes a file pattern to match after the input filename, and returns 0 on finding it or 11 on failure.