Count multiple occurrences of some text for each file under a directory
<p>I am trying to count multiple occurrences of some text for each file under a directory.  The following script is close to what I want but it does not count multiple occurrences on the same line:</p>

<pre><code>grep -rc 'blah' /some/path --include \*.txt
</code></pre>

<p>For example given two files:</p>

<pre><code>foo.txt
blah, hey blah
some more text

bar.txt
something blah
</code></pre>

<p>The above script produces:</p>

<pre><code>foo.txt:1
bar.txt:1
</code></pre>

<p>But the output I am looking for is*:</p>

<pre><code>foo.txt:2
bar.txt:1
</code></pre>

<p>I know that the total number of occurrences can be found in one file using grep and then piping the results to word count:</p>

<pre><code>grep -oh 'blah' foo.txt|wc -l
</code></pre>

<p>How to do this for multiple files to achieve the output as in my example* above?</p>

<p><strong>Update</strong></p>

<p>The best solution I could come up with is as follows:</p>

<pre><code>find /some/path -name '*.txt'|awk '{print "echo -n '\''" 
    $0 "\: '\'' &amp;&amp; grep -oh '\''blah'\'' " $0 "|wc -l"}'|bash
</code></pre>