How to run spell check on multiple files and display any incorrect words in shell script? How to run spell check on multiple files and display any incorrect words in shell script? bash bash

How to run spell check on multiple files and display any incorrect words in shell script?


You can install aspell with Homebrew on OS X. brew info aspell lists supported languages.

brew install aspell --lang=en,fi,jp

aspell check opens a file in an interactive spell checker:

for f in *.txt; do aspell check $f; done

aspell list prints all unrecognized words:

cat *.txt | aspell list | sort -u

Learned words are stored in .aspell.en.pws by default. You can also exclude words in ~/Library/Spelling/en after adding personal_ws-1.1 en as the first line.

aspell list --personal=$HOME/Library/Spelling/en


Using aspell, this will print each filename then a sorted list of misspelled words together with the number of times they occur:

for f in *.txt ; do echo $f ; aspell list < $f | sort | uniq -c ; done


You can do this with the find command. Doing so will work recursively and edit files in subdirectories too.

find . -type f -name "*.txt" -exec aspell check {} \;

Explanation:

  • find: Find...
  • .: in this directory
  • -type f: files (not directories)
  • -name "*.txt": ending in .txt
  • -exec aspell check {} \;: and run aspell on each of them.

The quoted wildcard is a bash construct. It might not be POSIX-compliant.