From owner-freebsd-stable@FreeBSD.ORG Sat Oct 2 21:21:11 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 DD2E71065673 for ; Sat, 2 Oct 2010 21:21:10 +0000 (UTC) (envelope-from 000.fbsd@quip.cz) Received: from elsa.codelab.cz (elsa.codelab.cz [94.124.105.4]) by mx1.freebsd.org (Postfix) with ESMTP id 7C3B58FC13 for ; Sat, 2 Oct 2010 21:21:10 +0000 (UTC) Received: from elsa.codelab.cz (localhost.codelab.cz [127.0.0.1]) by elsa.codelab.cz (Postfix) with ESMTP id 0E50819E027; Sat, 2 Oct 2010 23:21:09 +0200 (CEST) Received: from [192.168.1.2] (ip-86-49-61-235.net.upcbroadband.cz [86.49.61.235]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by elsa.codelab.cz (Postfix) with ESMTPSA id 485E419E023; Sat, 2 Oct 2010 23:21:06 +0200 (CEST) Message-ID: <4CA7A241.4050507@quip.cz> Date: Sat, 02 Oct 2010 23:21:05 +0200 From: Miroslav Lachman <000.fbsd@quip.cz> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: Damian Weber References: <4CA78EE3.9020005@quip.cz> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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:21:11 -0000 Damian Weber wrote: > > > 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? I am not AWK expert, so maybe you are right. I just found this difference between 7.x and 8.x. But if if works for other lines, why it doesn't work fot the first line too? Anyway, thank you for working examples, I will use them! Another working example from 6.4 is: awk -F "," '{ 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 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