bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incorrect string comparison by GAWK


From: Aharon Robbins
Subject: Re: Incorrect string comparison by GAWK
Date: Wed, 23 Dec 2009 04:52:30 +0200

Greetings. Re this:

> From: "Punde, Maghawan" <address@hidden>
> To: "address@hidden" <address@hidden>
> Date: Fri, 27 Nov 2009 15:26:58 +0530
> Subject: Incorrect string comparison by GAWK
>
> Hello,
>
> I want to report a rare care of incorrect string comparison by a GAWK. I
> am doing a fairly simple thing of counting lines identical "$1". The
> program behaves correctly for first 707 lines of input and beyond that
> it cannot be explained. Line 713 is the first line failure.
>
> =================COMMAND STARTS HERE ============================
> gawk 'BEGIN {curr = ""; } { curr = $1; if (prev != curr) { cnt = 1;} else 
> {cnt = cnt + 1;} prev = curr; printf "%4d %2d : %s\n",NR,cnt,$0; }' < in.txt 
> > out.txt
> ================= COMMAND END    HERE ============================

You need to change

        curr = $1

to

        curr = $1 ""

to force the value to be treated as a string. Your field values
are valid floating point numbers: 0e04 is 0 to the 4th power, so
gawk treats the values as numbers.

> ===================GAWK VERSION ==========================
> address@hidden 153: gawk --version
> GNU Awk 3.1.3

You should definitely upgrade. 3.1.7 is current.

Thanks,

Arnold




reply via email to

[Prev in Thread] Current Thread [Next in Thread]