Tag Archives: script

Simple single letter spell checker in bash

Here’s a small bash script. It checks if the given word is in dictionary and if not, assuming that it contains only a single character error, gives suggestions.

grep -i "^$word$" /usr/share/dict/words > /dev/null
if [ $? -eq 0 ]; then
   echo "Word in dictionary";
    echo "Word not in dictionary. Suggestions:"
    for i in $(seq 1 $l);
        regw=`echo $word | sed s/././$i`
        grep -i "^$regw$" /usr/share/dict/words

This was actually a question i had  in Tux of War, a shell scripting competition organized as a part of tathva at NIT Calicut. I got the sed expression from stackoveflow. It replaces just one letter of the word with ‘.’ in order in aloop, so that it would be a valid regex in grep to find the word suggestions.

I’m happy that my attempt works and I’m also sure there must be an efficient and easy method to do this! 😀