> From: "Punde, Maghawan" <Maghawa...@lsi.com>
> To: "bug-...@gnu.org" <bug-...@gnu.org>
> 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 ==========================
> mpunde@puneltc01 153: gawk --version
> GNU Awk 3.1.3
You should definitely upgrade. 3.1.7 is current.
Thanks,
Arnold