recursively count the words occurrence in the text files

Phil Meyer pmeyer at themeyerfarm.com
Thu Dec 30 18:48:36 UTC 2010


On 12/30/2010 11:34 AM, S Mathias wrote:
> mkdir one
> mkdir two
> mkdir three
>
> echo "word1 word2 word3">  one/asf.txt
> echo "word2 word4, word5">  one/asfcxv saf.txt
> echo "word1. word2">  one/dsgsdg.txt
>
> echo "word6, word3!">  two/sdgsd dsf.txt
> echo "word6">  two/ergd.txt
>
> echo "asdf, word2">  three/werdf.txt
> echo "word7, word8 word9 word10">  three/qwerb erfsdgdsg.txt
> echo "word4 word3">  three/web erg as.txt
>

Simplest would be:

grep -r -c word one two three

which produces:

one/asfcxv:1
one/asf.txt:1
one/dsgsdg.txt:1
two/ergd.txt:1
three/web:1
three/werdf.txt:1
three/qwerb:1

There are other options that will give you more precision, but basically 
I think that grep will give you what you want.

(If I understodd the question ... )


More information about the users mailing list