How to add second variable in awk nested if condition?

Hi Gurus,

I have a command to assign value based on input value.
current condition is

"if pattern matches "case", then assign "HOLD" else "SUCC"

right now, I need to add one more condition (variable name is VAR).
the condition is "

if pattern1 matches "case", then assign "HOLD" else if pattern2 not matches "exp", then SUCC else "IA".

when I try to add second variable and try a simple nested condition

 if pattern1 matches "case", then assign "HOLD" else if pattern2 not matches "exp", then SUCC

but the code doesn't work.

$cat file
aaa_case
bbb_xxx
ccc_xxx
ddd_xxx
eee_exp
 
$/usr/xpg4/bin/awk -v DUMMY="case" -v VAR="exp" 'tolower($0)~DUMMY{print "HOLD", $0} tolower($0)!~DUMMY and $0!~VAR {print "SUCC" ,$0}' OFS="," file
ON_HOLD,aaa_case
SUCCEEDED,aaa_case
SUCCEEDED,bbb_xxx
SUCCEEDED,ccc_xxx
SUCCEEDED,ddd_xxx
SUCCEEDED,eee_exp

Could anybody take a look this below code and let me know where I am wrong.

thanks in advance.

Try using && rather than and

---
And try something like:

awk -v DUMMY="case" -v VAR="exp" '{if(tolower($0)~DUMMY) s="HOLD"; else if($0~VAR) s="IA"; else s="SUCC"; print s, $0} file

Output:

HOLD aaa_case
SUCC bbb_xxx
SUCC ccc_xxx
SUCC ddd_xxx
IA eee_exp
2 Likes

Hi Scrutinizer.

the code works perfect.

As always, you gave me great help. thanks you very much.