recursively count the words occurrence in the text files

Rodolfo Alcazar Portillo nospaze at gmail.com
Fri Dec 31 10:08:05 UTC 2010


On Thu, 2010-12-30 at 10:34 -0800, S Mathias wrote:
> I just can't google for it:
> 
> I'm searching for a "bash" "one liner" (awk, perl, or anything) for this: 
> 
> there are text files, in several directories: 
> 
> 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
> 
> so it does the magic* "recursively":
> 
> $ SOMEMAGIC > output.txt
> cat output.txt
> asdf 1
> word1 2
> word2 4
> word3 3
> word4 2
> word5 1
> word6 2
> word7 1
> word8 1
> word9 1
> word10 1
> $

$ find . -type f -exec cat {} \;|sed -r 's/ /\n/g'|sort|uniq -c
----------------------------------------------
Rodolfo Alcazar Portillo - nospaze at gmail.com
otbits.blogspot.com / counter.li.org: #367962
----------------------------------------------
-VMS is a text-only adventure game. If you win you can use unix.
W. Davidson




More information about the users mailing list