Tuesday, April 9, 2013

Count the occurrences of a string per line in a file


cat exampleFile
text 1 text
text text 4 text 56
2
4
test
345
87 text

Count the occurrences of 'text' in exampleFile per line
awk -F "text" '{print NF-1}' exampleFile
2
3
0
0
0
0
1