I have a directory of files that is structured like this:
data/directory1/file1.xml
data/directory2/file2.xml
data/directory3/file3.xml
...
There are thousands of sub directories within data/, each with one xml file.
I would like to recursively scan data/ and look for three patterns, then echo the count of the pattern match (ideally) with a label before each. So, for my output, I'd like to see
Pattern 1 = 20
Pattern 2 = 100
Pattern 3 = 432
I've been able to use this to run these one at a time using:
grep -E -r 'Pattern 1' data/ | wc -l
grep -E -r 'Pattern 2' data/ | wc -l
grep -E -r 'Pattern 3' data/ | wc -l
Now I'm trying to put this all into a shell script with one argument, which would be parent directory of data/. Then output the count to each pattern to either standard output or count.txt.
Your help is appreciated!
-c
flag togrep
?grep -c
makes sense!