6

I have a text that has a number of misspelled words. I'd like to get a list of all those words, so for a text like this:

This is just a normall line with some speling mistakes in it. 

It would return:

normall speling

Is there way to do that, preferably using Linux tools, like aspell or vim?

3 Answers 3

4

You can use aspell -a to do this, and take the file from stdout. This will output the word with line number and alternate spellings:

cat example.txt | aspell -a

To clean up your list better, I'd use something more like:

cat aspell.txt | aspell -a | cut --delimiter ' ' --fields 2 | grep --invert-match '*'

Explaining the second set of commands: The output of aspell -a has a * for correctly spelled words, and mispelled words have output like this:

& dev 26 101: Devi, derv, DEC, Dec, deb, DE, def, div, Dave, dive, dove, DEA, Dee, dew, Del, Dem, Nev, Rev, deg, den, rev, Davy, deaf, defy, diva, TV

dev is the misspelled word here, which is in the second "column" when delimiting by spaces. So we pipe the aspell output to cut to get only the second column. We also pipe to grep to remove all the lines with *.

You can also append | sort | uniq to list misspelled words only once even if they appear in the text multiple times.

1
  • 2
    Please explain what your second set of commands do. May 25, 2018 at 9:19
2

I recently wanted to do this but I wasn’t particularly happy with the accepted answer so I researched the issue and came up with the following solutions, using four common spelling libraries/utilities.

Note: all quotes are from the man page for that particular utility.


Ispell

The -l or list option to ispell is used to produce a list of misspelled words from the standard input.

Input redirection can be used to read from a file:

ispell -l <example.txt

Aspell

One of aspell’s commands is list which, similar to the above ispell option, is used to

Produce a list of misspelled words from standard input.

This can also be combined with input redirection:

aspell list <example.txt

Hunspell

Hunspell also implements the -l option:

The "list" option is used to produce a list of misspelled words from the standard input.

While experimenting, I noticed it can also be used with a filename as an argument (without the need for input redirection):

hunspell -l example.txt

Enchant

Abiword’s Enchant spell-checker also supports the -l option:

List only the misspellings.

Likewise, Enchant also accepts a filename as an argument (while defaulting to standard input, if none provided):

enchant -l example.txt
1

My SpellCheck plugin has a :SpellCheck command that populates Vim's quickfix list with all spelling errors. You can then use Vim's built-in commands to navigate that list, or use mappings provided by the plugin to fix those errors directly from the list.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .