如何对多个字符串一起使用-v选项

时间:2019-04-11 19:07:47

标签: grep

如何避免多次放置-v的需要:

$ grep -v "^STAT" input.txt |grep -v "^FETCH" |grep -v "^EXEC" |more

grep -v“ ^ STAT | ^ FETCH | ^ EXEC”不起作用

input.txt内容

PARSING IN CURSOR #140624649413384 len=138 dep=1 uid=0 oct=47 lid=0 tim=2842971047106 hv=1640808739 ad='847b34d8' sqlid='33kmw45hwth93'
end if;
end;
END OF STMT
EXEC #140624649413384:c=938,e=1085,p=0,cr=0,cu=0,mis=0,r=1,dep=1,og=4,plh=0,tim=2842971047105
CLOSE #140624649413384:c=17,e=16,dep=1,type=1,tim=2842971047215
STAT #140624649392392 id=1 cnt=0 pid=0 pos=1 obj=0 op='UPDATE  USER$ (cr=2 pr=0 pw=0 time=418 us)'
EXEC #140624649361984:c=43,e=43,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=2529664852,tim=2842971056023
FETCH #140624649361984:c=162,e=162,p=0,cr=0,cu=0,mis=0,r=1,dep=1,og=4,plh=2529664852,tim=2842971056204
STAT #140624649392392 id=2 cnt=1 pid=1 pos=1 obj=1332839 op='TABLE ACCESS CLUSTER USER$ (cr=2 pr=0 pw=0 time=15 us cost=1 size=7 card=1)'
WAIT #0: nam='library cache lock' ela= 156 handle address=1880771256 lock address=6417871272 100*mode+namespace=8323075 obj#=384 tim=2842971047466

我更喜欢使用grep,因为它对我来说比awk / sed等要容易得多;)。

2 个答案:

答案 0 :(得分:1)

来自man grep

SYNOPSIS
       grep [OPTIONS] PATTERN [FILE...]
       grep [OPTIONS] [-e PATTERN]...  [-f FILE]...  [FILE...]

我建议:

grep -v -e "^STAT" -e "^FETCH" -e "^EXEC" input.txt | more

答案 1 :(得分:1)

grep -E -v "(STAT|FETCH|EXEC|...)" file

分别

grep -E -v "(STAT|FETCH|EXEC)" input.txt