Hi,
i am trying to count the fields in a file.
Input:
100,1000,,2000,3000,10/26/2012 12:12:30
200,3000,,1000,01/28/2012 17:12:30
300,5000,,5000,7000,09/06/2012 16:12:30
output:
Cout of the fileds for each row
6
5
6
awk -F"," '{print $NF}' file1.txt
When i try with above awk command i am getting the below output and it is not working as expected.
12:12:30
17:12:30
16:12:30
Any suggestion using awk command for couting the fields.
Scott
2
Use NF instead of $NF.
But your output with $NF is strange, given the field separator you've used.
thanks for swift responce.
i can find the total fileds in the row which is not equal to 6
awk -F"," '{print NF","$0}' |grep -v "^6"
Input
100,1000,,2000,3000,10/26/2012 12:12:30
200,3000,,1000,01/28/2012 17:12:30
300,5000,,5000,7000,09/06/2012 16:12:30
Output
5,200,3000,,1000,01/28/2012 17:12:30
i unable to print the only values not include the count
required output : fileds not having 6 and print only values and not include
200,3000,,1000,01/28/2012 17:12:30
i want to print only data not count in the output.
RudiC
4
Please use code tags for data as well!
Try
awk -F"," 'NF!=6'
200,3000,,1000,01/28/2012 17:12:30
No need for grep
. awk
will check the field count, and, if eq. 6, print the line, otherwise, not.