Monday, 24 November 2014

Terminal based Spell Check

Here's a cool little script I wrote (added to my .bashrc) file in order to test spellings, or to generate them when I don't remember them.

function spelling {
if [ $((`grep -c "^$1$" /usr/share/dict/american-english`)) -gt 0 ]; then
   echo -e "Spelling of\e[1;32m" `grep -m 1 "^$1$" \
    /usr/share/dict/american-english` "\e[0mseems fine"
   echo -e "\e[1;31mThere seems to be a mistake in spelling\e[0m"

The script is run quite simply by saying "spelling word-to-be-checked". For example,
spelling look
would say
Spelling of look seems fine
spelling louk
would say
There seems to be a mistake in spelling

Where this is extremely useful is when you cannot remember some part of the spelling of a word. For example allitaration or alliteration. Here, I can just use a regex.

spelling allit.ration
would say
Spelling of alliteration seems fine
thereby giving the right spelling.

No comments:

Post a comment