If else condition inside for loop of awk command in UNIX shell scripting

Hi ,
Please excuse me for opening a new thread i am unable to find out the syntax error
in my if else condition inside for loop in awk command ,
my actual aim is to print formatted html td tag when if condition (True) having string as "failed",
could anyone please advise what is the right syntax for the code.

awk 'BEGIN{RS="\n";
FS="|";
}
{
print "<TR>";
for (i = 1; i <= NF; i++)
{
if ( "$i" == "failed" )
{print "<TD align=left STYLE="background-color:#FF9933">" $i "</TD>";}
else
{print "<TD>" $i "</TD>";}
}
print "</TR>";
print "\n";
}' test_mail.txt 

getting the below error:

awk: cmd. line:9: {print "<TD align=left STYLE="background-color:#FF9933">" $i "</TD>";}
awk: cmd. line:9:                                               ^ syntax error
awk: cmd. line:15: }
awk: cmd. line:15:  ^ unexpected newline or end of string

Thanks,
Regards,
karthikram

Try escaping the inner double quotes:

... \"background-color:#FF9933\" ...

otherwise background-color:#FF9933 will be treated as awk code.

1 Like

Hi Scott,

Thanks it worked.

Thanks,
Regards,
karthikram