Batch spellchecking with find and aspell

Despite the availability of check-as-you-type spellcheckers (even for vim, which I use for all text editing), I still prefer to write a document and spell check it afterwards. There are several reasons for this. The first is that when I am writing a document, I don’t want the flow of my writing, and my concentration broken every time I make a typing error. The second is that I use my editor for a variety of tasks including writing ‘normal’ documents, writing code in a variety of languages, and writing documents that contain code and a lot of technical acronyms. I don’t want the visual noise of seeing a lot of ‘mis-spellings’ that I want to ignore, or to have to keep training the spell checker to ignore them.

I therefore tend to write a document, and then spell check it afterwards. Aspell is perfect for this, it supports a variety of (spoken) languages and document encodings and run-together words. Most importantly, it supports a range of filters, which filter reserved words in specific documents so that they don’t get checked. Modes I often use are --mode=tex (filter latex keywords) --mode=sgml and --mode=ccpp.

Checking multiple documents

To check a selection of documents, the -exec flag of the find command is aspell’s friend. For example, to check every file in every directory in the current directory:

find ./ -exec aspell -d, --master=british -c '{}' \;

Here {} corresponds to the output of the find command, and we delimit it with single quotes to allow for filenames that contain spaces. ‘\;’ signifies the end of the command to be executed by find.

This can be further supplemented by find’s regex support to filter the search results, and of course, the aspell filters:

 find ./ -iregex '.*\.[hs][tg]ml' -exec aspell -d, --master=british --mode=sgml -c '{}' \;

This will recursively find all files in the current directory and the directories beneath it that have the extension ‘.html’ or ‘.sgml’ (case insensitive), and run aspell on them ignoring all HTML and SGML tags.

Related Entries

About

I work at Birmingham Conservatoire as senior researcher and software development manager for the Integra Project. I live with my wife and three beautiful children in Birmingham, UK.» More...

Tag Cloud

Projects

-->
Close