
ファイルにどのパターンや単語がないかを知りたいです。例:
テスト.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
答え2
grepが一致しない場合は、名前をエコーできます。
$ for i in cindrella daniel polo; do grep -q "$i" test.txt || echo "$i"; done
cindrella
daniel
-q
サイレントモード、一致するものを見つけて終了