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
cat * | grep -c string
Here is a faster-than-grep AWK alternative way of doing this, which handles multiple matches of <url>
per line, within a collection of XML files in a directory:
awk '/<url>/{m=gsub("<url>","");total+=m}END{print total}' some_directory/*.xml
This works well in cases where some XML files don't have line breaks.
grep -oh string * | wc -w
will count multiple occurrences in a line