Linuxでegrepの反対のコマンドを実行しますか?

Linuxでegrepの反対のコマンドを実行しますか?

ファイルにどのパターンや単語がないかを知りたいです。例:

テスト.txt

marco 
polo
charlie 
anthony
john

egrep 'marco|polo' test.txt marcoとpoloを出力します。

しかし、ファイルに単語がない場合は、その単語を出力するコマンドが必要です。

たとえば、egrep 'cindrella|daniel|polo' test.txtポロではなくcindrellaとdanielを出力する必要があります。

ベストアンサー1

grepingを逆にしたいです。

printf "%s\n" cindrella daniel polo | grep -v -f test.txt
cindrella
daniel

どこ

  • -v逆のオプションです
  • -f test.txt入力リストのインポートtest.txt

おすすめ記事