Spell check a file using the command line, not interactively

I have a large text file containing many missing / unsuccessful English words. I am looking for a way to edit this file using the Linux spell checker. I found several ways to do this, but according to my customs, they all work interactively. I mean, after seeing a missed / bad word, they offer some corrections for the user, and he / she must choose one of them. Since my file is quite large and contains a lot of incorrect words, I cannot edit it this way. I am looking for a way to tell the caster who will replace all the wrong words using the first candidate. Is there any way to do this? does the a / hun spell have any option for this?

Sincerely.

+8
command-line linux spell-checking aspell hunspell
source share
2 answers

If you don’t need to replace every incorrect word, but just point out the errors and print the sentences in non-interactive mode, you can use ispell:

$ ispell -a < file.txt | grep ^\& > errors.txt 

Unfortunately, I don’t know any standard Linux utility that does what you request from the command line, although the emacs suggestion in the comments above comes close.

+5
source share

You can experiment with the following commands:

 yes 0 | script -c 'ispell text.txt' /dev/null 

or

 yes 1 | script -c 'aspell check text.txt' /dev/null 

But keep in mind that results can be bad even for simple things:

 $ echo The quik broown fox jmps over the laazy dogg > text.txt $ yes 0 | script -c 'ispell text.txt' /dev/null Script started, file is /dev/null Script done, file is /dev/null $ cat text.txt The quick brown fox amps over the lazy dog 

It seems even worse with aspell, so it's probably best to go with ispell.

You need a script command because some commands, such as ispell, do not want to be a script. Usually, you should output yes 0 to a command to simulate pressing the 0 key all the time, but some commands detect a script and refuse to cooperate:

 $ yes 0 | ispell text.txt Can't deal with non-interactive use yet. 

Fortunately, they can be fooled by the script command:

 $ yes 0 | script -c 'ispell text.txt' /dev/null Script started, file is /dev/null Script done, file is /dev/null 

You can use a file other than / dev / null to log the output:

 $ yes 0 | script -c 'ispell text.txt' out.txt Script started, file is out.txt Script done, file is out.txt $ cat out.txt Script started on Tue 02 Feb 2016 09:58:09 PM CET Script done on Tue 02 Feb 2016 09:58:09 PM CET 
+5
source share

All Articles