可以aspell
在管道模式下为 html 和 xml 文件输出行号而不是偏移吗?我无法逐行读取文件,因为在这种情况下aspell
无法识别封闭标签(如果标签位于下一行)。
4 回答
这将输出所有出现的带有行号的拼写错误的单词:
# Get aspell output...
<my_document.txt aspell pipe list -d en_GB --personal=./aspell.ignore.txt |
# Proccess the aspell output...
grep '[a-zA-Z]\+ [0-9]\+ [0-9]\+' -oh | \
grep '[a-zA-Z]\+' -o | \
while read word; do grep -on "\<$word\>" my_document.txt; done
在哪里:
- my_document.txt 是您的原始文档
- en_GB 是您的主要字典选择(例如尝试 en_US)
- aspell.ignore.txt 是 aspell 个人词典(示例如下)
- aspell_output.txt 是管道模式下 aspell 的输出(ispell 风格)
- result.txt 是最终结果文件
aspell.ignore.txt 示例:
personal_ws-1.1 en 500
foo
bar
示例 results.txt 输出(用于 en_GB 字典):
238:color
302:writeable
355:backends
433:dataonly
您还可以通过将最后一行更改grep -on
为grep -n
.
这只是一个想法,我还没有真正尝试过(我在 Windows 机器上:()。但也许你可以通过 head 管道传输 html 文件(有字节限制)并使用 grep 计算换行符来找到你的行数字。它既不高效也不漂亮,但它可能只是工作。
cat icantspell.html | head -c <offset from aspell> | egrep -Uc "$"
我使用以下脚本来执行拼写检查并解决aspell -a
/的尴尬输出ispell
。同时,该脚本还解决了2nd
aspell 无法识别序数 like 的问题,方法是简单地忽略 aspell 报告的所有不是它自己的单词的内容。
#!/bin/bash
set +o pipefail
if [ -t 1 ] ; then
color="--color=always"
fi
! for file in "$@" ; do
<"$file" aspell pipe list -p ./dict --mode=html |
grep '[[:alpha:]]\+ [0-9]\+ [0-9]\+' -oh |
grep '[[:alpha:]]\+' -o |
while read word ; do
grep $color -n "\<$word\>" "$file"
done
done | grep .
stdout
如果脚本的 是终端,您甚至会获得彩色输出,并且如果1
脚本发现拼写错误,您会获得退出状态,否则脚本的退出状态为0
.
此外,该脚本保护自己免受pipefail
,这是一个比较流行的选项,即在 a 中设置,Makefile
但不适用于此脚本。最后但并非最不重要的一点是,当它还匹配非 ASCII 字符(如德语和其他字符)时,该脚本显式使用[[:alpha:]]
而不是混淆。也确实如此,但这在某种程度上令人惊讶。[a-zA-Z]
äöüÄÖÜß
[a-zA-Z]
aspell pipe
//aspell -a
每ispell
输入一行输出一个空行(报错后)。
使用 awk 打印行号的演示:
$ aspell pipe < testFile.txt |
awk '/^$/ { countedLine=countedLine+1; print "#L=" countedLine; next; } //'
产生这个输出:
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.7-20110707)
& iinternational 7 0: international, Internationale, internationally, internationals, intentional, international's, Internationale's
#L=1
*
*
*
& reelly 22 11: Reilly, really, reel, rely, rally, relay, resell, retell, Riley, rel, regally, Riel, freely, real, rill, roll, reels, reply, Greeley, cruelly, reel's, Reilly's
#L=2
*
#L=3
*
*
& sometypo 18 8: some typo, some-typo, setup, sometime, someday, smote, meetup, smarty, stupor, Smetana, somatic, symmetry, mistype, smutty, smite, Sumter, smut, steppe
#L=4
与 testFile.txt
iinternational
I say this reelly.
hello
here is sometypo.
(仍然不如hunspell -u
(https://stackoverflow.com/a/10778071/4124767)好。但是 hunspell 错过了一些我喜欢的命令行选项。)