我想编写一个 bash 过滤器,它将获取一个由换行符分隔的句子文件并返回没有拼写错误的句子。我一直在考虑 aspell,但我不知道该怎么做。有任何想法吗?
问问题
1679 次
3 回答
2
这个管道应该给出你想要的结果。请注意,您应该将某些内容导入其中,因此请预先准备好例如cat input.txt |
进行快速测试。
while read line; do [ "$(ispell -l <<< "$line" | wc -l)" -gt 0 ] && echo "$line"; done
还要添加行号:
nl -b a -p | while read number line; do [ "$(ispell -l <<< "$line" | wc -l)" -gt 0 ] && echo "$number: $line"; done
如果您想返回拼写错误的行,只需替换-gt
为-le
(或替换&&
为||
,当然)
当然你可以将这些行保存为脚本,然后简单地做
script.sh < input.txt
如果你喜欢
于 2011-04-09T23:37:22.593 回答
2
这是一个执行您想要的脚本的脚本。
#!/bin/bash
# Regex for lines describing "good words":
# - empty lines (after each line of input, i.e. at the end)
# - lines with only a '*' (indicating a good word)
# - a line with '@(#) ' (at the start of the output)
# All other lines indicate a bad word.
good_words='^[*]?$|^@\(#\) '
while read # read one line of input
do
echo $REPLY | # pipe the line to aspell
aspell pipe | # let aspell check the line
egrep -q -v $good_words || # have a look if aspell found misspellings
# no words with mistake, output the line
echo $REPLY
done
于 2011-04-09T23:41:34.963 回答
0
grep -v "$(aspell list < file)" file
于 2011-04-10T02:26:54.513 回答