I’m trying to divide two fields (where sometimes the divisor might be zero) with Awk.
I thought this would work: awk -F, '{if ($6 != 0) print $3/$6}' <some file>
But it chokes with fatal: division by zero attempted even though I thought the “if” condition took care not to divide if field 6 is zero.
What am I overlooking?
“bar” != 0. if $6 is a string, the comparison fails, but when converted to a number for the division it evaluates to zero. Use
instead.