Tuesday, April 10, 2012

Count the number of occurances of a pattern in a file using awk

awk '{ for (i=1;i<=NF;i++) if ( $i == "word" ) count++ } END{print count}' filename

This will print the count of the occurance of  a pattern "word" in a file.

No comments:

 

Blogger news

Blogroll