匹配 2 个文件中的单词

Match words from 2 files

我有 2 个 txt 文件(words.txt 和 fail.txt)

words.txt

level4:the
level4:of
level4:and
level4:to
level4:a
level4:in
level4:for
level4:is
level4:on
level4:that
level4:by
level4:this
level4:with
level4:i
level4:you

fail.txt

the
of
and
to
a
in

如何获得一个列表,其中包含 words.txt 中除 fail.txt 之外的所有列表? 我需要获得的结果示例

level4:for
level4:is
level4:on
level4:that
level4:by
level4:this
level4:with
level4:i
level4:you

谢谢。

使用 awk:

awk -F: 'FNR==NR{fail[[=10=]]++; next} !( in fail)' fail.txt words.txt
level4:for
level4:is
level4:on
level4:that
level4:by
level4:this
level4:with
level4:i
level4:you

描述:

-F :                         # use : as delimiter
NR == FNR {                  # While processing the fail file
  fail[[=11=]]++                 # store the record in an array fail
  next                       # move to next record
}
{                            # while processing the words file
  !( in fail)              # print if 2nd field is not in fail array
}