count of record in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count of record in files
# 8  
Old 08-03-2012
Quote:
THis is fine but i want to write in a file to store them for future use
...then please add an output redirection to the end of the command (as you did in your example)!
# 9  
Old 08-03-2012
Either way shown will work, you just need to redirect the output to a file using
Code:
 >> filename

, so for example:

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

or

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}' >> output_filename


The second way is my preferred way as it is a oneliner.



Edit: Ninja'd by RudiC!

Last edited by spynappels; 08-03-2012 at 08:22 AM.. Reason: Edited to allow appending to file rather than over writing.
# 10  
Old 08-03-2012
It is fine , can we remove the path because it is writing the full path of the file with the 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 | awk '{ print $1, "|", $2 }' 
done

# 11  
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 -F "/"  '{ print $1, "|", $NF }'   
done

# 12  
Old 08-03-2012
Adopting pamu's example might behave unexpectedly if entered for the working directory and thus not providing any "/". Pls try
Code:
wc -l /src/dir/*|awk 'BEGIN {FS="[/ ]+"; print "count\t|filename"} {printf "%d\t|%s\n", $2, $NF}' >outfile

If you dont like the <TAB> char just remove the \t in the print statements.

Last edited by RudiC; 08-03-2012 at 10:24 AM.. Reason: typo...
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