[Discuss] Weird awk processing

David Rosenstrauch darose at darose.net
Thu May 2 19:17:27 EDT 2013


On 05/02/2013 03:52 PM, Jerry Feldman wrote:
> On 05/02/2013 01:11 AM, David Rosenstrauch wrote:
>> Just stumbled upon the most bizarre awk problem.  mawk and gawk are
>> showing 2 different results for the same code.  Can anyone shed any
>> light?
>>
>> TIA!
>>
>> DR

> I get the same results from the 2. The first thing I did was to run
> sample.txt through sed to convert the spaces to tabs. Certainly the
> correct result is the gawk result you got.

The issue apparently only occurred in certain versions of mawk.  (Most 
notably v1.3.3, which was installed onto my Ubuntu server.)

I (with some help from others) managed to pinpoint the issue earlier 
today, fortunately:  apparently mawk was interpreting "32e56067" and 
"32e56122" as numbers coded in scientific notation, interpreting them 
both as infinity, and then deciding they were equal!  The fix was to 
change this line:

curr_label=$1;

to this:

curr_label=""$1;

to force mawk to interpret $1 as strings.  Go figure!

Thanks,

DR




More information about the Discuss mailing list