From owner-freebsd-stable@FreeBSD.ORG Sat Oct 2 21:48:45 2010 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 930B3106564A for ; Sat, 2 Oct 2010 21:48:45 +0000 (UTC) (envelope-from dweber@htw-saarland.de) Received: from theia.rz.uni-saarland.de (theia.rz.uni-saarland.de [134.96.7.31]) by mx1.freebsd.org (Postfix) with ESMTP id 215BE8FC0C for ; Sat, 2 Oct 2010 21:48:44 +0000 (UTC) Received: from zdve-mailx.htw-saarland.de (zdve-mailx.htw-saarland.de [134.96.208.108]) by theia.rz.uni-saarland.de (8.14.1/8.14.0) with ESMTP id o92KwcmG023815; Sat, 2 Oct 2010 22:58:38 +0200 Received: from magritte.htw-saarland.de (magritte.htw-saarland.de [134.96.216.98]) by zdve-mailx.htw-saarland.de (8.13.8/8.13.8) with ESMTP id o92KwbKJ023288; Sat, 2 Oct 2010 22:58:37 +0200 (CEST) Date: Sat, 2 Oct 2010 22:58:34 +0200 (CEST) From: Damian Weber To: Miroslav Lachman <000.fbsd@quip.cz> In-Reply-To: <4CA78EE3.9020005@quip.cz> Message-ID: References: <4CA78EE3.9020005@quip.cz> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: clamav-milter 0.96 at zdve-mailx X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (theia.rz.uni-saarland.de [134.96.7.31]); Sat, 02 Oct 2010 22:58:38 +0200 (CEST) X-AntiVirus: checked by AntiVir MailGate (version: 2.1.2-14; AVE: 7.9.4.72; VDF: 7.10.12.111; host: AntiVir1) Cc: freebsd-stable Subject: Re: is there a bug in AWK on 6.x and 7.x (fixed in 8.x)? X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Oct 2010 21:48:45 -0000 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 > 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