awk +如何在awk命令中执行OR操作

时间:2010-07-22 07:59:17

标签: awk

我有以下文件

your  Answer  = AA
your  Answer  = AB
your  Answer  = CD
your  Answer  = XY 
your  Answer  = DD

验证我运行以下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 "}'

我的问题:如何在一个awk命令上执行相同操作以运行5 awk命令?

回应“你的答案= AA”| awk'/ = AA | AB | CD | XY | DD / {print“传递”}'

3 个答案:

答案 0 :(得分:1)

你已经关闭了:你只需要将候补者放在一个组中,这样等号总是在那里:

echo "your Answer = AA" | awk '/= (AA|AB|CD|XY|DD)/ {print " passed "}'

答案 1 :(得分:0)

awk -F"=" '$2~/A[AB]|[CD]D|XY/{print "passed"}' file

答案 2 :(得分:0)

or(echo "your  Answer  = AA",echo "your  Answer  = AA") | awk '/= AA/{print " passed "}'

尝试这样的事情。