{"id":14500,"date":"2026-08-21T01:00:00","date_gmt":"2026-08-21T05:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14500"},"modified":"2026-08-05T19:55:56","modified_gmt":"2026-08-05T23:55:56","slug":"play-a-word-game-at-the-command-line","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14500","title":{"rendered":"Play a word game at the command line"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14500\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">When I need a break, I like to relax by playing a fun puzzle game or word game. I enjoy the British quiz show <em>Countdown<\/em>\u2014this features two games, a <a href=\"https:\/\/www.both.org\/?p=5852\">Numbers game<\/a> and a <em>Letters<\/em> game, which are both fun to play as a \u201cbreak\u201d when I\u2019m working. Actually, I prefer the other version of the show with the comedians, <em>8 Out of 10 Cats Does Countdown<\/em>, but both shows feature the same games.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Letters game is a simple puzzle where you need to find the longest word using a list of nine random letters. Just pick a selection of consonants and vowels from the Scrabble letter tiles, and see what words you can come up with. With a bit of creativity, you can also play this game at the Linux command line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Letters by frequency<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I found a list online of the letter frequency in Scrabble, which I used as my starting point to play this word game on Linux:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>A 9\nB 2\nC 2\nD 4\nE 12\nF 2\nG 3\nH 2\nI 9\nJ 1\nK 1\nL 4\nM 2\nN 6\nO 8\nP 2\nQ 1\nR 6\nS 4\nT 6\nU 4\nV 2\nW 2\nX 1\nY 2\nZ 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save that to a new file called <code>letters.freq<\/code> so we can use it as the starting point to play the Letters game.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Print that many of each letter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We can use the frequency distribution to generate a random selection of letters to play with. To start, we need a short <strong>awk<\/strong> command that reads the <code>letters.freq<\/code> list and prints <em>that many<\/em> of each letter. This is a basic <code>for<\/code> loop, where the <strong>awk<\/strong> command uses the second field of each line as <em>the number of times<\/em> to print out the first field. That is, for <code>C 2<\/code>, the command would print the letter C two times:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ awk '{for (n=0; n&lt;$2; n++) {print $1}}' letters.freq | head\nA\nA\nA\nA\nA\nA\nA\nA\nA\nB<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see in this output, the letter A has a frequency of 9, and the letter B has a frequency of 2. The <strong>head<\/strong> command only prints the first ten lines by default, so we can see all nine instances of the letter A, and the first instance of the letter B.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To print out a list of all <em>vowels<\/em> from the letter frequency list, we only need to add a <em>regular expression<\/em> to the <strong>awk<\/strong> command, so we print only vowels:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ awk '\/^&#91;AEIOU]\/ {for (n=0; n&lt;$2; n++) {print $1}}' letters.freq | head\nA\nA\nA\nA\nA\nA\nA\nA\nA\nE<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We can <em>negate<\/em> the regular expression using <code>^<\/code> before the list of vowels to print only <em>non-vowels<\/em> as the output. This generates a list of just the consonants:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ awk '\/^&#91;^AEIOU]\/ {for (n=0; n&lt;$2; n++) {print $1}}' letters.freq | head\nB\nB\nC\nC\nD\nD\nD\nD\nF\nF<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Pick a few random letters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I find a mix of five consonants and four vowels makes for a good enough selection that I can find some decent words. To select only four random entries from this list, we can use the <strong>shuf<\/strong> command to randomize or shuffle the results. The <code>-n<\/code> option makes <strong>shuf<\/strong> print only a few lines, such as <code>shuf -n 4<\/code> to print only four random vowels and <code>shuf -n 5<\/code> to list five random consonants:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ awk '\/^&#91;^AEIOU]\/ {for (n=0; n&lt;$2; n++) {print $1}}' letters.freq | shuf -n 5\nT\nT\nG\nT\nS\n\n$ awk '\/^&#91;AEIOU]\/ {for (n=0; n&lt;$2; n++) {print $1}}' letters.freq | shuf -n 4\nO\nE\nI\nI<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Putting it all together<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To play the word game from the Linux command line, I like to put the commands into a script. Let\u2019s call it <code>letters.bash<\/code>. Then I can run one instruction to generate a list of four random vowels and five random consonants. Collecting this in a script also makes things tidier, because we can save the letter frequency list (<code>letters.freq<\/code>) in a file somewhere like <code>$HOME\/lib\/letters.freq<\/code> and reference the path. This means we can run the script from anywhere, and the script will always be able to find the letter frequency file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nlist=$HOME\/lib\/letters.freq\nawk '\/^&#91;^AEIOU]\/ {for (n=0; n&lt;$2; n++) {print $1}}' $list | shuf -n 5\nawk '\/^&#91;AEIOU]\/ {for (n=0; n&lt;$2; n++) {print $1}}' $list | shuf -n 4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save this as <code>letters.bash<\/code> and make it executable. Then run the script to generate a list of five random consonants and four random vowels:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ chmod +x letters.bash\n$ .\/letters.bash\nY\nR\nT\nT\nB\nE\nA\nI\nE<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Try playing the game for yourself and see what words you can come up with. The rules for making words are simple: use letters only once, but no abbreviations and no proper nouns. Use regular words only. If you\u2019re not sure if a word is a proper noun, use the Linux <code>\/usr\/share\/dict\/words<\/code> file to look it up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, with the above list of letters, I was able to find TIRE (4 letters), BEAR (4 letters), TRIBE (4 letters), and BITTY (5 letters). The longest word I could find was BATTERY (7 letters).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Play it your own way<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This shows a basic way to generate nine random letters to play the Letters game. The script prints each letter on a separate line, as five consonants and four vowels.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One improvement you can make to the game is to use the <strong>shuf<\/strong> command to \u201cshuffle\u201d the nine letters into a random order, and the <strong>fmt<\/strong> command to \u201cformat\u201d them into a single line of output. This makes the letters easier to see. For example, you can add these extra commands on the command line like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/letters.bash | shuf | fmt\nI E R P J U V S E<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example, I can find the words PIER (4 letters) and PEER (4 letters). The longest word I could find is REVISE (6 letters) but maybe you can find a longer one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A better way would to be to change the script to do this for you. I\u2019ll leave that as a challenge for <em>you<\/em> to make the game your own, and make other changes, so you can play it your own way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Need a break? Try this fun word game at the command line.<\/p>\n","protected":false},"author":33,"featured_media":6046,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[100,69],"tags":[104,147],"class_list":["post-14500","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-fun","tag-command-line","tag-fun"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14500"}],"version-history":[{"count":3,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14500\/revisions"}],"predecessor-version":[{"id":14503,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14500\/revisions\/14503"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/6046"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}