[Top][All Lists]
[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: |
Wed, 14 Sep 2005 10:54:06 +0200 |
User-agent: |
Mutt/1.4.1i |
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