Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2010 15:30
What would you like to do?
Script to count word frequency.
#!/usr/bin/env ruby -w
text =
words = text.split(/[^a-zA-Z]/)
freqs =
words.each { |word| freqs[word] += 1 }
freqs = freqs.sort_by { |x, y| y }
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