[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Strange behavior in gawk
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] Strange behavior in gawk |
Date: |
Sat, 6 Dec 2014 22:29:51 -0500 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Sun, Dec 07, 2014 at 01:52:04AM +0100, Davide Brini wrote:
> This is becoming sort of a FAQ, please read
>
> https://www.gnu.org/software/gawk/manual/gawk.html#Field-Splitting-Summary
>
> the box titled "Changing FS Does Not Affect the Fields". To workaround your
> issue you can use split(), or change FS before awk attempts to read the
> line in question (ie, at the end of the previous one).
Another solution is to reassign $0. If you change your script to say:
/:/ {
FS=":"
$0 = $0
print "NF = " NF " - " $0
}
/\./ {
FS="."
$0 = $0
print "NF = " NF " - " $0
}
Then you will get the desired results:
NF = 3 - 1:2:3
NF = 3 - 4:5:6
NF = 4 - .a.b.c
NF = 4 - .e.f.g
Regards,
Andy