grep 表示所有没有特定单词的行

gkm*_*hit 2 grep

我有一个文件 fileA.txt

Batman.plist
Green Arrow.plist
Hawkgirl.plist
EOPrototypes.plist
Person.plist
EOPrototypes.plist
EOJavellinPrototypes.plist
Sinestro
Slomon Grundy.plist
Batman Beyond.plist
EORedRobin
EORavenPrototypes.plist
Run Code Online (Sandbox Code Playgroud)

现在,如果我想获得的所有线路为此与plist和不包含的字Prototype。到目前为止我有

grep -v "Prototype" fileA.txt | grep -E "*plist$"
Run Code Online (Sandbox Code Playgroud)

输出是

Batman.plist
Green Arrow.plist
Hawkgirl.plist
Person.plist
Slomon Grundy.plist
Batman Beyond.plist
Run Code Online (Sandbox Code Playgroud)

这正是我想要的,

但是有没有更好的方法来做到这一点?

Sté*_*las 7

grep -v Prototype | grep 'plist$'
Run Code Online (Sandbox Code Playgroud)

可能是最好的。您可以使用一个带有sed或的命令awk(或使用grep其他人已经显示的非标准扩展名)来完成它:

sed '/Prototype/d;/plist$/!d'
Run Code Online (Sandbox Code Playgroud)

或者

awk '/plist$/ && ! /Prototype/'
Run Code Online (Sandbox Code Playgroud)

但这并不一定会更有效率。