[SWLUG] locating bits of code in large number of files
Justin Mitchell
justin at discordia.org.uk
Sun Oct 17 10:31:40 UTC 2004
On Sun, 2004-10-17 at 09:53, Geraint A Edwards wrote:
> On Fri, Oct 15, 2004 at 11:14:36PM +0100 or thereabouts, Neil Jones wrote:
> > All I really need is a count of the number of files with and without the code
>
> find . -name \*.html | \
> xargs grep -c getS | \
> awk ' /:0$/{n++;next}
> {m++}
> END{print m,"matching,",n,"non-matching"}'
>
There is as always a different, and i think simpler, way to get a count
of how many files match the pattern.
grep -rl searchstring . --include \*.html | wc -l
the options to grep say to recurse, only print the filename once for
each match, and only check .html files (note the \ to stop the shell
expanding the *). which gives you a list of filenames one per line, so
we simply ask wc to count the lines for us.
More information about the Swlug
mailing list