可以在管道模式下输出行号而不是偏移吗?

时间:2011-04-06 14:14:20

标签: html xml spell-checking aspell

对于html和xml文件,aspell可以输出行号而不是管道模式的偏移吗?我无法逐行读取文件,因为在这种情况下aspell无法识别封闭标记(如果标记位于下一行)。

3 个答案:

答案 0 :(得分:3)

这将输出所有出现的拼写错误单词的行号:

# 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来打印整行。

答案 1 :(得分:1)

这只是一个想法,我还没有真正尝试过(我在Windows机器上:()。但也许你可以通过head(带字节限制)管道html文件并使用grep计算换行符找到你的行号。它既不高效又不漂亮,但它可能会起作用。

cat icantspell.html | head -c <offset from aspell> | egrep -Uc "$"

答案 2 :(得分:0)

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 -uhttps://stackoverflow.com/a/10778071/4124767)。但是hunspell错过了一些我喜欢的命令行选项。)