linux平台查找字典中没有出现的单词

luv*_*ven 0 linux bash

这里的文本可能有一些词,每一行都有一个词。我接受它作为命令行参数。例如纺织品a.txt是这样的:

about
catb
west
eastren
Run Code Online (Sandbox Code Playgroud)

而我想要做的是找到字典中没有的单词,如果单词是字典单词,则在文本文件中将其删除。我使用以下命令:

word=$1
grep "$1$" /usr/share/dict/linux.words -q
for word in $(<a.txt) 
do
  if [ $word -eq 0 ]
  then
    sed '/$word/d' 
  fi
done
Run Code Online (Sandbox Code Playgroud)

什么都没有发生。

Sun*_*eep 7

grep 根据我的理解,单独就足够了

$ grep -xvFf /usr/share/dict/linux.words a.txt 
catb
eastren
Run Code Online (Sandbox Code Playgroud)

catb并且eastren是在 中找不到的词/usr/share/dict/linux.words。使用的选项是

   -x, --line-regexp
          Select only those matches that exactly match the whole line.  For a regular expression pattern, this is
          like parenthesizing the pattern and then surrounding it with ^ and $.

   -v, --invert-match
          Invert the sense of matching, to select non-matching lines.

   -F, --fixed-strings
          Interpret PATTERN as a list of fixed strings (instead of regular expressions), separated  by  newlines,
          any of which is to be matched.

   -f FILE, --file=FILE
          Obtain patterns from FILE, one per line.  If this option is used multiple times or is combined with the
          -e  (--regexp)  option,  search  for  all  patterns  given.  The empty file contains zero patterns, and
          therefore matches nothing.
Run Code Online (Sandbox Code Playgroud)