bash - How can I use multiple pattern in awk? -
bash - How can I use multiple pattern in awk? -
i have command this:
tac "$log" | awk -v pattern="$var1" '$9 ~ pattern {print; exit}'
it prints lastly line if $9
equals $var1
.
i need utilize "and" , "or" multiple patterns this:
print if $9 ~ pattern , (if $9 ~ pattern2 or if $9 ~ pattern3)
how can utilize awk this?
tac "$log" | \ awk -v pat1="$p1" \ -v pat2="$p2" \ -v pat3="$p3" \ '$9 ~ pat1 && ($9 ~ pat2 || $9 ~ pat3) { print; exit }'
however if don't need pass in patterns outside, can of in regexp:
awk ... '$9 ~ pat1 && $9 ~ /pat2|pat3/ { print; exit }'
bash awk
Comments
Post a Comment