I want to count all the records in a table through awk but NR prints record nos of all records not the total count. I even tried:
NF==4,count++{print count}
But its not working properly How can I do it through awk?
awk with NF (number of fields) variable. NF is a built-in variable of awk command which is used to count the total number of fields in each line of the input text. Create any text file with multiple lines and multiple words.
NR: NR command keeps a current count of the number of input records. Remember that records are usually lines. Awk command performs the pattern/action statements once for each record in a file.
wc. The wc command is used to find the number of lines, characters, words, and bytes of a file. To find the number of lines using wc, we add the -l option. This will give us the total number of lines and the name of the file.
Please show a sample of your file and what you want to do with it (show the desired output ) next time. Just guessing what you want,
awk 'NF==4{count++} END {print count}' file
the total number of records is indicated by NR.
awk 'END{print NR}' file1 file2
the total number of records currently is denoted by FNR.
awk 'END{print FNR}' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With