How to get compiler-like messages from ispell or aspell

139 Views Asked by At

Spell checking on multiple text files.

Having an output of the form as 'gcc' produces it:

   intro/main.txt:12:                  'hierarchie' -- orthograph
   concepts/detail/experiment.txt:12:  'propper' -- orthograph

is a good formal description of a 'todo' list. Also, it enables spell checking by IDEs such as vim and emacs. They can parse this content and jump to the place at focus at button press.

I would like to run ispell/aspell on multiple text files and generate a list of errors in a compiler-error-like fashion.

1

There are 1 best solutions below

0
Frank-Rene Schäfer On BEST ANSWER
for file in $(find . -name "*.tex" -type f); \
  do for word in $(cat $file | aspell list); \
     do grep -sHIno "\b$word\b" $file \
        | sort -u; 
     done; 
  done > tmp.log

That is, the first for loop iterates over the files of concern--here the '.tex' files in the directory subtree. The nested for loop iterates over the words that 'aspell' complains about. The 'grep' command greps the line number and produces the compile-like message. Option '-o' prints only the matched part, i.e. the misspelled word. 'sort -u' ensures that two errors on one line do not produce double output.

Redirecting this to '> tmp.log', setting vim to 'set makeprg=cat', and then using ':make tmp.log' enables a convenient stepping through all spelling errors in the document.

Any comment is welcome.