改行で区切られた文のファイルを取得し、スペルミスのない文を返す 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 に答える