Hello everyone, this is my first post and my first script. It now does what it is supposed to but I wonder if there is a better way of doing this.
Purpose: There is a directory with files that have names like these: file1_1.zip, file1_2.zip, file1_3.zip, file2_1.zip, file2_2.zip, file2_3.zip .... fileN_3.zip. Each of these zip files contains several files with names like this nameoffile.###. My objective is to count the number of files with the form nameoffile.### and output to a text file with this format (#1, #2, #3 represents the number of nameoffile.### files in filex_1.zip, filex_2.zip, filex_3.zip respectively):
file1 #1 #2 #3
file2 #1 #2 #3
file3 #1 #2 #3
.
.
fileN #1 #2 #3
This is what I did:
Code:
#!/bin/bash
for file in *1.zip
do
halffile=`basename "$file" 1.zip`
itsfile1=`unzip -l "$halffile"1.zip | grep PolParams.* |wc -l`
itsfile2=`unzip -l "$halffile"2.zip | grep PolParams.* |wc -l`
itsfile3=`unzip -l "$halffile"3.zip | grep PolParams.* |wc -l`
oneline="$halffile $itsfile1 $itsfile2 $itsfile3"
echo $oneline >> resultsforspreadsheet.txt
done
exit 0
It does what I want but I dont know if its efficient, correct, proper or what not...
Any comments or suggestions would be much appreciated.