Ubuntu

通過終端在文件中查找英文單詞

  • May 30, 2013

如何通過linux命令行查找並列印文件中包含的英文單詞?

GNU grep 有以下選項:

grep --only-matching --ignore-case --fixed-strings --file /usr/share/dict/british-english-insane /path/to/file.txt

這會輸出每行一個找到的字元串。這/usr/share/dict/british-english-insane是 Debian 軟體包提供的詞彙表wbritish-insane

他,好笑!

file=/usr/share/licenses/common/GPL3/license.txt
dict=/usr/share/dict/cracklib-small

while read word; do
   grep >/dev/null -i "\<$word\>" $file &&
       printf 'Word "%s" found in GPLv3...\n' $word
done < $dict

輸出 :

Word a found in GPLv3...
Word ability found in GPLv3...
Word about found in GPLv3...
(...)

cracklib-small 文件隨包cracklib http://sourceforge.net/projects/cracklib

引用自:https://unix.stackexchange.com/questions/49641