对每一行进行拼写检查

发布于 2024-10-31 06:10:29 字数 82 浏览 1 评论 0原文

我想编写一个 bash 过滤器,它将采用换行符分隔的句子文件并返回没有拼写错误的句子。我一直在考虑 aspell 但我不知道该怎么用它。有什么想法吗?

I'd like to write a bash filter that will take a file of newline-separated sentences and return sentences that are not misspelled. I've been thinking about aspell but I'm not sure what to do with it. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩物 2024-11-07 06:10:29

该管道应该给出您想要的结果。请注意,您应该将一些内容输入其中,因此请在前面添加 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 (或替换 && > by ||,当然)


当然,您可以将这些行保存为脚本,然后

script.sh < input.txt

如果您愿意,可以简单地执行

This pipe should give the results you want. Note that you should pipe something into this, so prepend e.g. cat input.txt | for a quick test.

while read line; do [ "$(ispell -l <<< "$line" | wc -l)" -gt 0 ] && echo "$line"; done

To also prepend a line number:

nl -b a -p | while read number line; do [ "$(ispell -l <<< "$line" | wc -l)" -gt 0 ] && echo "$number: $line"; done

If you want to return misspelled lines instead, just replace -gt by -le (or replace && by ||, of course)


Of course you can save these lines as a script, and then simply do

script.sh < input.txt

if you so prefer

滥情稳全场 2024-11-07 06:10:29

这是一个可以完成您想要的操作的脚本。

#!/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

Here is a script which does what you want.

#!/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
猫九 2024-11-07 06:10:29
grep -v "$(aspell list < file)" file
grep -v "$(aspell list < file)" file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文