[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug in latest awk release
From: |
Mirco Meniconi |
Subject: |
Re: bug in latest awk release |
Date: |
Thu, 15 Sep 2005 16:23:59 +0200 (CEST) |
Dear Stepan,
Thank you for your very clear explanation,
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 ... ???
Best Regards
--- Stepan Kasal <address@hidden> ha scritto:
> Hello,
>
> On Tue, Sep 13, 2005 at 10:11:40AM +0200, Mirco Meniconi wrote:
> > ~/gawk-3.1.5/gawk -v FS="\t" '{print $1}' f.txt
>
> this is correct command. Alternatively, you might use:
>
> gawk 'BEGIN{FS="\t"} {print $1}' f.txt
>
> or
>
> gawk '{print $1}' FS="<tab>" f.txt
>
> (The <tab> would have to be real tab character.)
>
> But the following awk program is buggy:
>
> > #~/gawk-3.1.5/gawk 'FS="\t" {print $1}' f.txt
>
> Before we get to this program, let me remind that the awk program
> consists of PATTERN ACTION pairs.
>
> So you can use
> $2 != "" {print}
> to select lines with non-empty second field.
>
> So in your example:
> FS="\t" {print $1}
> the "condition" is the assignment to FS. It is always true, so all
> lines are printed. But the FS is changes only when the condition is
> evaluated. This means that the first line is split according to
> the default FS. Then the FS is changed, so the second line will be
> split using tab as the FS. But the first line is already split, and
> $1 was already computed.
>
> Perhaps reading the gawk manual ("info gawk") or a fine book about
> awk might help you. Then your first attempt would be to place the
> assignment to BEGIN.
>
> With regards,
> Stepan Kasal
>
___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it