#!/bin/bash # Copyright (C) 2011, 2013-2014 Luke Shumaker # Usage: hangman-helper word not [-l] # is the known word, with unknown characters replaced with '.'. # is a sequence of the characters that are known to not be in the word. # # Without the `-l` flag, it produces a list of possible completions. # # With the `-l` flag, it produces a list of letters, # sorted by the number of times they appear in the normal list word=$1 not=$2 flag=$3 grep -ix "$word" /usr/share/dict/words | grep -iv "['$not]" | { if [[ "$flag" = '-l' ]]; then tr 'A-Z' 'a-z' | sed 's/\(.\)/\1\n/'g | sort | uniq -c | sort -n else cat fi }