bash 如何对多个文件运行拼写检查并在 shell 脚本中显示任何不正确的单词?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12799741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run spell check on multiple files and display any incorrect words in shell script?
提问by simont
I have a few files I wish to spellcheck. Normally I would open these in vim, run :set spelland do the changes. It's really teadious to open files and manually check if I've misspelt any words since the last check, however.
我有几个文件要进行拼写检查。通常我会在 中打开这些vim,运行:set spell并进行更改。然而,打开文件并手动检查自上次检查以来我是否拼错了任何单词真的很烦人。
Is there a way I can run a spell-check on a lot of files and display any incorrectly-spelt words found, along with the filename, so that I can go and change them? I don't want to open every file, check if it's "clean", then open the next and repeat.
有没有办法可以对许多文件进行拼写检查,并显示发现的任何拼写错误的单词以及文件名,以便我可以更改它们?我不想打开每个文件,检查它是否“干净”,然后打开下一个并重复。
I can't find any POSIX spellcheck utility. Some Red-Hat based Linux distributions allegedly have spellor similar, but I'd prefer a cross-platform(ish) method. I know vimcanspellcheck - is there any way of spellchecking without doing it all manually? It'd be fantasticif I could shell-script a solution.
我找不到任何 POSIX 拼写检查实用程序。据称某些基于 Red-Hat 的 Linux 发行版具有spell或类似的功能,但我更喜欢跨平台(ish)方法。我知道vim可以拼写检查 - 有没有什么方法可以在不手动完成所有操作的情况下进行拼写检查?如果我能用 shell 编写一个解决方案,那就太棒了。
I'm running OS X, for what it's worth.
我正在跑步OS X,为了它的价值。
回答by Lri
You can install aspell with Homebrew on OS X. brew info aspelllists supported languages.
您可以在 OS X 上使用 Homebrew 安装 aspell。brew info aspell列出支持的语言。
brew install aspell --lang=en,fi,jp
aspell checkopens a file in an interactive spell checker:
aspell check在交互式拼写检查器中打开文件:
for f in *.txt; do aspell check $f; done
aspell listprints all unrecognized words:
aspell list打印所有无法识别的单词:
cat *.txt | aspell list | sort -u
Learned words are stored in .aspell.en.pwsby default. You can also exclude words in ~/Library/Spelling/enafter adding personal_ws-1.1 enas the first line.
学习的单词.aspell.en.pws默认存储在。您还可以~/Library/Spelling/en在添加personal_ws-1.1 en为第一行后排除单词。
aspell list --personal=$HOME/Library/Spelling/en

