count of record in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count of record in files
# 1  
Old 08-03-2012
count of record in files

Hi all,

I have written a scripts which count number of lines in all the files in a directory and write in a text file. I don't know how to format it while writing. OS suns solaris 10

my scripts is as below
Code:
for i in /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/ *.LOG
do
  echo "File size of $i is"
  #wc -l $i
  wc -l < $i
  #sum= $(( sum + $(wc -l < "${i}") ))
done>lines.txt

i want the output like this
Code:
count    File_name
20|1.csv
45|3.csv
30|4.csv

Any help will be much appriciated

Thanks

Last edited by Franklin52; 08-06-2012 at 03:28 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-03-2012
Code:
for i in /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/*.LOG
do
wc -l $i
done

# 3  
Old 08-03-2012
you don't need a script. Please try (and comment)
Code:
wc -l /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/*.LOG|awk 'BEGIN {print "count\tfilename"} {printf "%d\t|%s\n", $1,$2}'

wc will count all the files for you, and awk will do the formatting.
# 4  
Old 08-03-2012
I know this, But i want to put a '|' between count and file name

Quote:
Originally Posted by pamu
Code:
for i in /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/*.LOG
do
wc -l $i
done

# 5  
Old 08-03-2012
Have you tried RudiC's solution?
# 6  
Old 08-03-2012
THis is fine but i want to write in a file to store them for future use
Quote:
Originally Posted by RudiC
you don't need a script. Please try (and comment)
Code:
wc -l /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/*.LOG|awk 'BEGIN {print "count\tfilename"} {printf "%d\t|%s\n", $1,$2}'

wc will count all the files for you, and awk will do the formatting.
# 7  
Old 08-03-2012
try this.....

Code:
for i in /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/*.LOG 
do 
wc -l $i | awk '{ print $1, "|", $2 }' 
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

2. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

3. Shell Programming and Scripting

Record count checking for multiple files through for-loop

Hi Friends, I wrote one shell script to check the record count in two files and that will send us the notification activity if found zero record count. What i did is I created for loop and checking the count for both of the files but what is happening is for first file has data then it's... (13 Replies)
Discussion started by: victory
13 Replies

4. Shell Programming and Scripting

Validating the record count

Hi , I am having a text file with several records., it has a header record and trailer record. The header record has the number of rows (records) found in the text file and time-stamp. The footer record has the total number of records ( along with the header and trailer., Suppose: wc -l... (4 Replies)
Discussion started by: cratercrabs
4 Replies

5. UNIX for Dummies Questions & Answers

Reduce the count on the 98 record by 2,

recod,amount,noofaccount,count 98,+00000187865779787,00319,000000640/ 99,+00000187865779787,00001,000000642/ thsi is my input file my question is 1) Reduce the count on the 98 record by 2 (6 Replies)
Discussion started by: sgoud
6 Replies

6. Shell Programming and Scripting

Comparison of record count of two files

Hi, I have one text file and zip file in UNIX directory.The Zip file contains another text file. For Ex: Text File Name = Req_file.txt Zip file Name= Response_file.txt_04072009_121548.gz Zip file contains one text file that name is Response_file.txt I want to compare the record... (1 Reply)
Discussion started by: praka
1 Replies

7. Shell Programming and Scripting

replaying a record count with another record count

i use unix command to take the record count for a file1 awk 'END{print NR}' filename i already have a file2 which conatin the count like ... .. rec_cnt=100 .. .. I want to replace the record in the file2 using the record i take from file1. suggest me some simple ways of doing it... (2 Replies)
Discussion started by: er_zeeshan05
2 Replies

8. Shell Programming and Scripting

record count

i have a file named file_names.dat where there are several files along with their path. exp: /data1/dir1/CTA_ACD_20071208.dat /data1/dir1/CTA_DFG_20071208.dat i want to write a script which will create a csv file with the name of the file and record count of that file the output file... (4 Replies)
Discussion started by: dr46014
4 Replies

9. Shell Programming and Scripting

Need help with Isql record count

What I am trying to do is check if the database query returned any records. If no records returned then output a message else output results to a file. Right now if I take out the if and else statements the code runs fine and sends the email. If no records returned the email sends the column... (4 Replies)
Discussion started by: johnu122
4 Replies

10. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question