Re: recursively count the words occurrence in the text files
- From: Aaron Konstam <akonstam@xxxxxxxxxxxxx>
- Date: Thu, 30 Dec 2010 16:20:36 -0600
On Thu, 2010-12-30 at 10:34 -0800, S Mathias wrote:
I just can't google for it:Attached is a python program that counts the number of words in a file.
I'm searching for a "bash" "one liner" (awk, perl, or anything) for this:
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
- Follow-Ups:
- Re: recursively count the words occurrence in the text files
- From: Joe Zeff
- Re: recursively count the words occurrence in the text files
- References:
- recursively count the words occurrence in the text files
- From: S Mathias
- recursively count the words occurrence in the text files
- Prev by Date: Re: Fedora 14 and Nvidia 460 Fermi
- Next by Date: Re: Yum vs. PackageKit
- Previous by thread: Re: recursively count the words occurrence in the text files
- Next by thread: Re: recursively count the words occurrence in the text files
- Index(es):