第三章:Creating Utilities--27.增加一个本地词典
生活随笔
收集整理的這篇文章主要介紹了
第三章:Creating Utilities--27.增加一个本地词典
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
? ?做完了上面的第25、26個腳本后,我們想要自己手動增加一個本地詞典,這樣就不用在每次遇到一個新的單詞后,都會一遍遍的報錯了。
代碼:
1 #!/bin/sh 2 3 # spelldict.sh -- 使用'aspell'特性以及一些過濾以便 4 # 允許命令行拼寫檢查給定的輸入文件 5 6 # 不可避免的,你會發(fā)現(xiàn),有些詞匯是錯誤的,但你認(rèn)為 7 # 它們是正確的。簡單的將它們保存在一個文件中,一次 8 # 一行,并且確定變量'okaywords'指向這個文件。 9 10 okaywords="$HOME/okaywords" 11 tempout="/tmp/spell.tmp.$$" 12 spell="aspell" # 根據(jù)需要修改 13 14 trap "/bin/rm -f $tempout" EXIT 15 16 if [ -z "$1" ]; then 17 echo "Usage: spell file | URL" >&2 18 exit 1 19 elif [ ! -f $okaywords ]; then 20 echo "No personal dictionary found. Create one and return this command." >&2 21 echo "Your dictionary file: $okaywords" >&2 22 exit 1 23 fi 24 25 for filename 26 do 27 $spell -a < $filename | \ 28 grep -v '@(#)' | sed "s/\'//g" | \ 29 awk '{if(length($0) > 15 && length($2) > 2) print $2}' | \ 30 grep -vif $okaywords | \ 31 grep '[[:lower:]]' | grep -v '[[:digit:]]' | sort -u | \ 32 sed 's/^/ /' > $tempout 33 34 if [ -s $tempout ]; then 35 sed 's/^/${filename}: /' $tempout 36 fi 37 done 38 39 exit 0運行腳本:
這個腳本需要在命令行上提供一個或多個文件名
運行結(jié)果:
首先,一個空的個人字典,txt內(nèi)容摘錄自愛麗絲漫游記: $ spelldict ragged.txt ragged.txt: herrself ragged.txt: teacups ragged.txt: Gryphon ragged.txt: clamour 有兩個詞拼錯了,所以準(zhǔn)備用echo命令把它們加到okaywords文件中:$ echo "Gryphon" >> ~/.okaywords $ echo "teacups" >> ~/.okaywords 擴展了詞典文件后的檢查結(jié)果如下:$ spelldict ragged.txt ragged.txt: herrself ragged.txt: clamourps: 這3章的單詞檢查,對我個人而言真的很無趣。期待后續(xù)的精彩腳本吧。
轉(zhuǎn)載于:https://www.cnblogs.com/lalala23456/archive/2013/01/07/2848788.html
總結(jié)
以上是生活随笔為你收集整理的第三章:Creating Utilities--27.增加一个本地词典的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: input onblur事件在chrom
- 下一篇: Chapter1 CLR的执行模式