Created
January 18, 2010 15:30
-
-
Save rgreenjr/280096 to your computer and use it in GitHub Desktop.
Script to count word frequency.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
text = IO.read(ARGV.first) | |
words = text.split(/[^a-zA-Z]/) | |
freqs = Hash.new(0) | |
words.each { |word| freqs[word] += 1 } | |
freqs = freqs.sort_by { |x, y| y } | |
freqs.reverse! | |
freqs.each { |word, freq| puts sprintf("%20s %s", word, freq.to_s) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment