Wednesday, 24 April 2013

Unix: Awk script to count number of occurences of a word in the file

Following 'awk' script will print number of occurences of "word" in "file.txt"
 

$awk 'BEGIN{num=0}{for(i=0;i<NF;i++){if($i=="word") num++;}}END{print num;}' file.txt

No comments:

Post a Comment