Word Frequency

Word Frequency


This script will scan a text file and count the number of times each word appears in the document. There are several reasons to extract word counts, or word frequencies, from a document. One example is for the cryptographic analysis of a cipher text that has been encrypted with a shift cipher. I find word frequency to be interesting in my own writing, too. Running this script shows me which words I use most often and, with a few tweaks, can show those that are not part of my daily vocabulary.

The Code

 unless ARGV[0] puts "\nYou need to include a file to test." puts "Usage: ruby wordFreq.rb file_to_test.txt" ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.