Script to get Row Count of ZIP Files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to get Row Count of ZIP Files
# 1  
Old 04-14-2009
Script to get Row Count of ZIP Files

Hi,
I have some data files in a zipped format.(eg: aa.gz).I would like to know the number or rows in each zip file(May be populate the file name and line numbers into a text file).I know the commands wc -l and gunzip,.But how I will create a shell script for this to extract each files and get row count?I am using ksh.

Thanks,

Last edited by abhilash_menon; 04-14-2009 at 11:55 PM..
# 2  
Old 04-15-2009
An example how it could look like:
Code:
#!/usr/bin/ksh

IN_DIR=./tmp
OUTFILE=infofile

ls -1 ${IN_DIR} |\
while read LINE; do
        ROW_COUNT=`zcat ${IN_DIR}/${LINE}| wc -l`
        printf "%-10s%s\n" "${ROW_COUNT}" "${LINE}" >> ${OUTFILE}
done

exit 0

# 3  
Old 04-15-2009
I modified slightly.It prints.But for the rowcount, it is giving as 0 always.Any inputs?
Code:
#!/usr/bin/ksh
OUTFILE=infofile
cd /home/XYZ/ASH/;
for i in /home/XYZ/ASH/*.gz ;
do
ROW_COUNT=`zcat /home/XYZ/ASH/$i| wc -l`
        printf "%-10s%s\n" "${ROW_COUNT}" "$i" >> $OUTFILE
done

exit 0


Last edited by vidyadhar85; 04-15-2009 at 07:55 PM.. Reason: code tag added
# 4  
Old 04-15-2009
Quote:
Originally Posted by abhilash_menon
I modified slightly.It prints.But for the rowcount, it is giving as 0 always.Any inputs?
#!/usr/bin/ksh
OUTFILE=infofile
cd /home/XYZ/ASH/;
for i in /home/XYZ/ASH/*.gz ;
do
ROW_COUNT=`zcat /home/XYZ/ASH/$i| wc -l`
printf "%-10s%s\n" "${ROW_COUNT}" "$i" >> $OUTFILE
done

exit 0
yup....
Code:
 
#!/usr/bin/ksh
OUTFILE=infofile
cd /home/XYZ/ASH/
for i in *.gz 
do
ROW_COUNT=`zcat /home/XYZ/ASH/$i| wc -l`
printf "%-10s%s\n" "${ROW_COUNT}" "$i" >> $OUTFILE
done
 
exit 0


Last edited by vidyadhar85; 04-15-2009 at 08:30 PM..
# 5  
Old 04-15-2009
'ls' is useless here. Also you don't need a trailing ';'
Code:
#!/usr/bin/ksh
OUTFILE=infofile

for i in /home/XYZ/ASH/*.gz
do
   ROW_COUNT=$(zcat "${i}" | wc -l)
   printf "%-10s%s\n" "${ROW_COUNT}" "$i" >> $OUTFILE
done

# 6  
Old 04-16-2009
Thanks vgersh.I don't know why it still prints the count as 0 only for all the files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split files based on row delimiter count

I have a huge file (around 4-5 GB containing 20 million rows) which has text like: <EOFD>11<EOFD>22<EORD>2<EOFD>2222<EOFD>3333<EORD>3<EOFD>44<EOFD>55<EORD>66<EOFD>888<EOFD>9999<EORD> Actually above is an extracted file from a Sql Server with each field delimited by <EOFD> and each row ends... (8 Replies)
Discussion started by: amvip
8 Replies

2. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

3. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. UNIX for Advanced & Expert Users

Zip the files if count is more than 0 and send a mail

All, I am new to shell scripting and trying to get the count of files that starts with error and with extension .out, if the count is greater than 0 and zip the file and send an email with the content of error.out file, here is my script cd /temp testcount =$('find . -name '*.out' -print |... (4 Replies)
Discussion started by: luckydoll
4 Replies

6. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

7. Shell Programming and Scripting

row count of 60 files in one file

hi all plz some unix guy help me in this i have 60 files which will have some records i want to find the total number of records in all the 60 files like file1 has 60 and file2 has 70 record i want to sum all these and find total row count in 60 files (5 Replies)
Discussion started by: er_zeeshan05
5 Replies

8. Shell Programming and Scripting

script to take row count

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (5 Replies)
Discussion started by: er_zeeshan05
5 Replies

9. UNIX for Dummies Questions & Answers

row count of all files with more than 0 byte

Hi, Is there any way to get count number of lines in all files which have more than o bytes in current directory for example : in /user/sri/ there are 3 files abc 0 bytes def 5 bytes ghi 10 bytes i need to get wc -l for all files which have > 0 bytes at a time ..is... (6 Replies)
Discussion started by: sri2005
6 Replies

10. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question