Work the Shell - More Fun with Word and Letter Counts

Determine the frequency of letters within a document (and become unbeatable at Hangman).

Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Letter frequency

opie's picture

Samuel Morse would have loved your article, as I did. In devising Morse code, he assigned the briefest codes to the most frequently used letters. Lacking your routine and access to /usr/share/dict/words, he based his count on the number of letters in sets of printers' type, according to ( The figures he came up with for the most common letters were:

12,000 E
9,000 T
8,000 A, I, N, O, S

In contrast, Zs occupied the least letter space in typesetters' cabinets, with only 200 on hand.

As a result, E and T in Morse code require single key presses, one short and the other long (dot and dash, respectively). Other letters may require four key presses, combining dots and/or dashes. Optimization makes a difference; even so sending 5 words per minute in Morse code is a challenge for the novice; 20 words per minute the mark of a pro! poses some interesting questions that shell scripters could have fun with. For example,

Are there any English words containing the same letter three times in a row?

Are there any words in the English language that use all five vowels with no intervening consonants or have the five vowels in the right order?

Too easy? Try: What is the longest one-syllable English word?

I remember before you could look virtually everything up on the Internet, being surprised how difficult it was to code a routine for breaking words into syllables. Not because the coding itself was hard but because detailing the underlying rules was such a challenge.

One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix