How To Perform Mathematical Operation Within If in awk?

Hi All,

I am using an awk script as below:

awk -F'|' 'BEGIN{OFS="|";} { if ($1==$3 && $3==$7 && $7==$13 && $2==$6 && $6==$11 && $15-$14+1==$11) print $0"|""TRUE"; else print $0"|""FALSE"; }' tempfile.txt

In above script, all conditions are being checked except the one which is underlined. Can any one please help me to identify the error?

Thanks
Angshuman

Try enclosing that part in brackets:

... && ($15-$14+1==$11)) ...

The order of operations in that is ambiguous. Parenthesize defensively.

( ($15-$14)+1==$11 )

According to the standards, in awk all of the following are required to produce identical results:

if ($6==$11 && $15-$14+1==$11)
if (($6==$11) && ($15-$14+1==$11))
if (($6==$11) && (($15-$14+1)==$11))
if (($6==$11) && ((($15-$14)+1)==$11))

angshuman,
What was the input line and what field separator were you using when $15-$14+1==$11 did not give you the results you expected; or if you changed the value of $11 , $14 , or $15 after reading the line, what values did they have when $15-$14+1==$11 gave you unexpected results?

Corona688,

+ and - are associative, so I don't know how there could be any ambiguity.