awk + how to perform OR action in awk command
I have the following file
your Answer = AA
your Answer = AB
your Answer = CD
your Answer = XY
your Answer = DD
to verify all answers I run the following awk
echo "your Answer = AA" | awk '/= AA/{print " passed "}'
echo "your Answer = AA" | awk '/= AB/{print " passed "}'
echo "your Answer = AA" | awk '/= CD/{print " passed "}'
echo "your Answer = AA" | awk '/= XY/{print " passed "}'
echo "your Answer = AA" | awk '/= DD/{print " passed "}'
My question: How to do the same on one awk command in ple开发者_如何学Cace to run 5 awk command?
Like
echo "your Answer = AA" | awk '/= AA|AB|CD|XY|DD/{print " passed "}'
You're close: you just need to put the alternates in a group so the equal sign is always there:
echo "your Answer = AA" | awk '/= (AA|AB|CD|XY|DD)/ {print " passed "}'
awk -F"=" '$2~/A[AB]|[CD]D|XY/{print "passed"}' file
or(echo "your Answer = AA",echo "your Answer = AA") | awk '/= AA/{print " passed "}'
Try something like this.
精彩评论