A Spellchecker in awk
In this section, we present a program for checking spelling. Even though all Unix systems have spell, and many also have aspell or ispell, it is instructive and useful to implement our own program. This illustrates the power of awk, and gives us a valuable program that can be used identically on every platform that has awk.
We make a strong distinction between checking and correcting spelling. The latter requires knowledge of the format of the text, and invariably requires human confirmation, making it completely unsuited to batch processing. The automatic spelling correction offered by some web browsers and word processors is even worse because it is frequently wrong, and its second-guessing your typing quickly becomes extremely annoying.
The emacs text editor offers
three good solutions to spelling assistance during text entry: dynamic
word completion can be invoked on demand to expand a partial word,
spelling verification of the current word can be requested by a single
keystroke, and the flyspell
library
can be used to request unobtrusive colored highlighting of suspect
words.
As long as you can recognize misspellings when they are pointed out to you, it is better to have a spellchecker that reports a list of suspect words, and that allows you to provide a private list of special words not normally present in its dictionary, to reduce the size of that report. You can then use the report to identify errors, repair them, regenerate the report (which should ...
Get Classic Shell Scripting now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.