Register
It is currently Wed Apr 16, 2014 2:15 am

Counting files in a list of zip files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Mon Feb 23, 2009 11:38 pm   

Joined: Mon Feb 23, 2009 11:28 pm
Posts: 1
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.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP