grep - How to count total number of matches of regular expression per file on AIX -


grep used display lines containing match of specified pattern. there way in aix display total number of matches of pattern in each file searched? say, every match in every line should counted.

i tried grep -c pattern filename, counts each matching line once many matches contains.

finding 3 occurrences of b. in file:

$ cat file bc d f bg h  $ awk '{c+=gsub(/b./,"")} end{print c+0}' file 3 

the above work awk on os (except old, broken awk of course).


Comments