Tried using grep -c option to find the number of times a string is found in a text file, but this bypasses multiple occurences of the string on the same line.
Is there a way of capturing total matches of a string in a text file?
You might try awk (nawk in my case since I'm using Solaris 7). The global substitute command, gsub returns the number of substitiutions made in $0. I just cycle thru x.file counting the number made.
Great help. One question, the line I am reading is very long, and I'm getting a "too long" error. Any other way of accomplishing this with nawk or awk?
the last script can produce wrong out put for example
if in the file you have "*string*" this occurence will be counted too
try other thing.
good luck
-SimoYaz
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.