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

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

Re: bug in latest awk release


From: Stepan Kasal
Subject: Re: bug in latest awk release
Date: Fri, 16 Sep 2005 18:52:55 +0200
User-agent: Mutt/1.4.1i

Dear Mirco,

On Thu, Sep 15, 2005 at 04:23:59PM +0200, Mirco Meniconi wrote:
> anyway let me tell you that the command  
> #~/gawk-3.1.5/gawk 'FS="\t" {print $1}' f.txt 
> works well using the SGI compiled verison of awk (where well means how I would
> have expected before your esplanation) .... maybe this is due to the
> not-complete compatibility between the standard Awk and the Gnu-Awk ... ???

as you might have observed from other answers, this is because of
a bug in SGI awk.  The GNU awk is compatible with the standard.

The mistake is a very natural one, let me explain:
though each  textbook explains that awk splits the record into fields as
soon as it is read, most awk implementations contain an optimization:

It is quite probable that the fields won't be needed and the record
will be used (or discarded) as a whole.  Thus the field splitting would
be waste of time.  So many implementations defer the field splitting to
the time when the first record is actually used.

But when you use this optimization, you have to be careful to maintain
consistent semantics.  When you decide to split the record, you have to
use the value of FS from the time when the record was read, not the
current one.

The SGI awk apparently did only the first half of the optimization,
yielding the incorrect behaviour.  (I mean the "well" behaviour, as
you named it.  ;-)

Hope this explains it,
        Stepan




reply via email to

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