Re: recursively count the words occurrence in the text files



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:

Attached is a python program that counts the number of words in a file.
This could easily be slightly altered and combined with find to do what
you want.

--
=======================================================================
"Plaese porrf raed." -- Prof. Michael O'Longhlin, S.U.N.Y. Purchase
=======================================================================
Aaron Konstam telephone: (210) 656-0355 e-mail: akonstam@xxxxxxxxxxxxx
#!/usr/bin/env python
import string

def WordsOccur():
fileName = raw_input("Enter the name of the file: ")
f=open(fileName,"r")
wordList=string.split(f.read())
f.close()

occursDict={}
for word in wordList:
occursDict[word] = occursDict.get(word, 0) +1
print "File %s has %d words (%d are unique)" \
% (fileName, len(wordList), len(occursDict) )
print occursDict

if __name__ == '__main__':
WordsOccur()
--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines