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
Grep only solution which I tested with grep for windows:
grep -ro "pattern to find in files" "Directory to recursively search" | grep -c "pattern to find in files"
This solution will count all occurrences even if there are multiple on one line. -r
recursively searches the directory, -o
will "show only the part of a line matching PATTERN" -- this is what splits up multiple occurences on a single line and makes grep print each match on a new line; then pipe those newline-separated-results back into grep with -c
to count the number of occurrences using the same pattern.