How to count the number of lines appearing in a text file with AWK only?

I am writing an AWK script that takes a list of dates and formats it into a list that is easier to read. I could not do that.

The real problem is this. After displaying the list, I want to display how many times “2010” appears in the text file.

How should I do it? I was looking for days, and I came up with absolutely nothing.

+3
source share
2 answers
awk '{ for (i=1;i<=NF;i++) if ( $i == "2010" ) count++ } END { print count }' myfile.txt
+2
source
awk -F"2010" 'NF>0 { count += NF-1 } END { print 0+count }
+3
source

All Articles