I have a bunch of log files. I need to find out how many times a string occurs in all files.
grep -c string *
returns
... f
The AWK solution which also handles file names including colons:
grep -c string * | sed -r 's/^.*://' | awk 'BEGIN{}{x+=$1}END{print x}'
Keep in mind that this method still does not find multiple occurrences of string on the same line.
string