is there a bug in AWK on 6.x and 7.x (fixed in 8.x)?

poyopoyo at puripuri.plala.or.jp poyopoyo at puripuri.plala.or.jp
Sun Oct 3 20:42:22 UTC 2010


At Sun, 3 Oct 2010 15:09:35 +0200,
Roubíček Zdeněk wrote:
> >> awk 'FS="," { print $1"-"$2 }' GeoIPCountryWhois.csv

This code is equivalent to

awk '(FS=","){} { print $1"-"$2 }' GeoIPCountryWhois.csv

so I think it is OK not to separate the first line with ",".
However, from the latest one-true-awk/FIXES source we have in src/contrib,

| Nov 26, 2009:
|         fixed a long-standing issue with when FS takes effect.  a
|         change to FS is now noticed immediately for subsequent splits.

AWK seems intentionally changed this behaviour. When FS has been changed,
working line is immediately re-parsed with new FS. This explains
why 8.x awk print *intended* $1"-"$2 though older and GNU ones do not.

> I met the very same problem some time ago, not a bug, feature.
> 
> http://www.mail-archive.com/freebsd-questions@freebsd.org/msg55958.html
> 
> Still, one interesting question remains, why 8.x behaves in a different way then the previous versions.

Now both are their own feature.
Conclusion: avoid ambiguous code as far as it could.

-- 
kuro


More information about the freebsd-stable mailing list