Date: Sat, 2 Oct 2010 22:58:34 +0200 (CEST) From: Damian Weber <dweber@htw-saarland.de> To: Miroslav Lachman <000.fbsd@quip.cz> Cc: freebsd-stable <freebsd-stable@freebsd.org> Subject: Re: is there a bug in AWK on 6.x and 7.x (fixed in 8.x)? Message-ID: <alpine.BSF.2.00.1010022239070.72341@magritte.htw-saarland.de> In-Reply-To: <4CA78EE3.9020005@quip.cz> References: <4CA78EE3.9020005@quip.cz>
index | next in thread | previous in thread | raw e-mail
On Sat, 2 Oct 2010, Miroslav Lachman wrote:
> Date: Sat, 02 Oct 2010 21:58:27 +0200
> From: Miroslav Lachman <000.fbsd@quip.cz>
> To: freebsd-stable <freebsd-stable@freebsd.org>
> Subject: is there a bug in AWK on 6.x and 7.x (fixed in 8.x)?
>
> I think there is a bug in AWK in base of FreeBSD 6.x and 7.x (tested on 6.4
> i386 and 7.3 i386)
>
> I have this simple test case, where I want 2 columns from GeoIP CSV file:
>
> awk 'FS="," { print $1"-"$2 }' GeoIPCountryWhois.csv
>
> It should produce output like this:
>
> # awk 'FS="," { print $1"-"$2 }' GeoIPCountryWhois.csv | head -n 5
> "1.0.0.0"-"1.7.255.255"
> "1.9.0.0"-"1.9.255.255"
> "1.10.10.0"-"1.10.10.255"
> "1.11.0.0"-"1.11.255.255"
> "1.12.0.0"-"1.15.255.255"
>
> (above is taken from FreeBSD 8.1 i386)
>
> On FreeBSD 6.4 and 7.3 it results in broken first line:
>
> awk 'FS="," { print $1"-"$2 }' GeoIPCountryWhois.csv | head -n 5
> "1.0.0.0","1.7.255.255","16777216","17301503","AU","Australia"-
> "1.9.0.0"-"1.9.255.255"
> "1.10.10.0"-"1.10.10.255"
> "1.11.0.0"-"1.11.255.255"
> "1.12.0.0"-"1.15.255.255"
>
Are you sure the command above contains a valid variable assignment?
The following works on both 7.3-STABLE and 8.1-STABLE
$ awk -v FS="," '{ print $1"-"$2; }' GeoIPCountryWhois.csv | head -n 5
"1.0.0.0"-"1.7.255.255"
"1.9.0.0"-"1.9.255.255"
"1.10.10.0"-"1.10.10.255"
"1.11.0.0"-"1.11.255.255"
"1.12.0.0"-"1.15.255.255"
The following works as well
$ awk '{ print $1"-"$2; }' FS="," GeoIPCountryWhois.csv | head -n 5
"1.0.0.0"-"1.7.255.255"
"1.9.0.0"-"1.9.255.255"
"1.10.10.0"-"1.10.10.255"
"1.11.0.0"-"1.11.255.255"
"1.12.0.0"-"1.15.255.255"
Or, using a BEGIN section for assignment...
$ awk 'BEGIN {FS=","} { print $1"-"$2 }' GeoIPCountryWhois.csv | head -n 5
"1.0.0.0"-"1.7.255.255"
"1.9.0.0"-"1.9.255.255"
"1.10.10.0"-"1.10.10.255"
"1.11.0.0"-"1.11.255.255"
"1.12.0.0"-"1.15.255.255"
As a side note, gawk shows the following output on 7-STABLE and 8-STABLE
$ gawk 'FS="," { print $1"-"$2 }' GeoIPCountryWhois.csv | head -n 5
"1.0.0.0","1.7.255.255","16777216","17301503","AU","Australia"-
"1.9.0.0"-"1.9.255.255"
"1.10.10.0"-"1.10.10.255"
"1.11.0.0"-"1.11.255.255"
"1.12.0.0"-"1.15.255.255"
... which means the new behaviour of awk on 8-STABLE seems to break
compatibility with gawk at that point.
-- Damian
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.00.1010022239070.72341>
