Re: recursively count the words occurrence in the text files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux