Total record count of all the file present in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Total record count of all the file present in a directory
# 8  
Old 10-24-2017
Quote:
Originally Posted by STCET22
Hi All,
Thank you all for your help.
@Ravinder,
As I'm new to awk part ,could you kindly explain the code for my understanding.
Hello STCET22,

Could you please go through following and do let me know if this helps you.(Please run code as mentioned in POST#2 only as this is only for explanation purposes.)
Code:
awk '
END{                    ###So this is awks END section which will be executed when ALL the Input_file(s) are done with reading by awk. 
print NR+1-length(ARGV) ###Now doing print of value of NR+1-length(ARGV) where NR value is the value of all the lines of Input_files(total of all lines of all files) then adding 1 to it and
                        ###Subtracting the value of length of array ARGV, array named ARGV is the default array for awk which will have the total number of Input_file(s) passed to it.
}                       ###So let's say you passed 3 files so its value will be 3 and value of headings will also be 3 so I am subtracting those lines which have headings in them as per your request.
' *.txt                 ###Mentioning all the .txt Input_file(s) here.

Thanks,
R. Singh
# 9  
Old 10-24-2017
length(array) gives the number of array elements, and is a GNU extension. The standard only knows length(string). And ARGC!
--
Another standard awk
Code:
awk 'FNR>1 {n++} END {print n+0}' *.txt

increment n if the record number of the current file is greater than 1.
At the END print n; the n+0 casts n to the number 0 in case it's unset.

Last edited by MadeInGermany; 10-24-2017 at 05:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Speed : awk command to count the occurrences of fields from one file present in the other file

Hi, file1.txt AAA BBB CCC DDD file2.txt abc|AAA|AAAabcbcs|fnwufnq bca|nwruqf|AAA|fwfwwefwef fmimwe|BBB|fnqwufw|wufbqw wcdbi|CCC|wefnwin|wfwwf DDD|wabvfav|wqef|fwbwqfwfe i need the count of rows of file1.txt present in the file2.txt required output: AAA 2 (10 Replies)
Discussion started by: mdkm
10 Replies

2. UNIX for Dummies Questions & Answers

Count total image in directory

Dear all, I have a directory consisted of files in .jpg, .jpeg etc..all of them are image 20140411030143_62811159403_92886.jpg 5/11/2014 15:01 197K 20140415024737_62811618747_116460.jpg 4/15/2014 14:47 17K 20140415031003_62811618747_109192.jpg 4/17/2014 15:10 17K... (4 Replies)
Discussion started by: radius
4 Replies

3. Shell Programming and Scripting

Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file... just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file.. tried with grep and while... (6 Replies)
Discussion started by: msathees
6 Replies

4. Shell Programming and Scripting

Help with sum total number of record and total number of record problem asking

Input file SFSQW 5192.56 HNRNPK 611.486 QEQW 1202.15 ASDR 568.627 QWET 6382.11 SFSQW 4386.3 HNRNPK 100 SFSQW 500 Desired output file SFSQW 10078.86 3 QWET 6382.11 1 QEQW 1202.15 1 HNRNPK 711.49 2 ASDR 568.63 1 The way I tried: (2 Replies)
Discussion started by: patrick87
2 Replies

5. Shell Programming and Scripting

csv file - adding total to a trailer record

Hi, I have a script which creates and modifies a csv file. I have managed to do everything I need to do apart from 1 thing. I need to append a trailer record to the file. I need this line to hold the total of an entire column of the csv file (skipping the 1st line which is a header). Can... (2 Replies)
Discussion started by: mcclunyboy
2 Replies

6. Shell Programming and Scripting

perl script on how to count the total number of lines of all the files under a directory

how to count the total number of lines of all the files under a directory using perl script.. I mean if I have 10 files under a directory then I want to count the total number of lines of all the 10 files contain. Please help me in writing a perl script on this. (5 Replies)
Discussion started by: adityam
5 Replies

7. UNIX for Advanced & Expert Users

Count total file downloaded using FTP

Hi All, I'm developing a FTP script as below: ftp -v -n <IP_ADDRESS> << EOF user avery jSqaqUU2 lcd /directory/folder/ ascii prompt mget * bye EOF I would like to enhance the script to count the total file downloaded. For example, once the script run i want the message "Total <n>... (1 Reply)
Discussion started by: cas553
1 Replies

8. Shell Programming and Scripting

To find the count of records from tables present inside a file.

hi gurus, I am having a file containing a list of tables.i want to find the count of records inside thes tables. for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file. ... (1 Reply)
Discussion started by: navojit dutta
1 Replies

9. 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