Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make Hunspell print the line numbers of the misspelled words?

I am trying to use Hunspell to correct an essay I have written. Unfortunately, it is useless to me, as long as it doesn’t print the line numbers of the misspelled words.

So right now I am using the -a option, in order to be able to pipe it into the hunspell command. The man page says, that the -L option would “Print lines with misspelled words.” But I don’t see any difference in the output.

This is what I do right now:

$ cat myessay.txt | hunspell -d en_US,de_DE -a -L

An example output looks like this:

& JavaServer 3 412: Java Server, Java-Server, Javasee

The word “JavaServer” is on line 78, and as explained by the man page, it has an offset of 412 characters on that line.

Is there something I am missing? Is there an easy solution to this problem, or do I really have to pipe each line into Hunspell to find out at which line number it was?

Thanks in advance.

like image 891
devsnd Avatar asked May 16 '12 11:05

devsnd


1 Answers

Now, I actually downloaded the sources of Hunspell and got down to business. There is an undocumented -u option that gives me an output I can comfortably work with:

$ hunspell -u -d en_US,de_DE myessay.txt

This does the trick for printing line numbers using the German and the American dictionaries. Alternatively, you can use the -U option to get an excerpt of the text, as well. Other undocumented command-line options are -u2 and -u3.

But be careful: Those switches are experimental and the source code says, that those functions are lacking Unicode support.

From the Hungarian documentation:

  • -u: Display typical errors in the file with a replacement proposal.
  • -u2: Typical bugs and their fixes which can be executed with sed.
  • -U: If you want to accept all the suggestions received with the -u option, the -U switch will automatically replace Hunspell and send the modified file to the standard output. Example patch: hunspell -U original_file >patch_file. The error output also shows patches again, similar to the -u switch.

Some output examples:

  • -u: Line 2: liveration -> liberation
  • -u2: 2s/liveration/liberation/g; # liveration
  • -u3: (null):2: Locate: liveration | Try: liberation
like image 174
devsnd Avatar answered Sep 21 '22 08:09

devsnd