From owner-freebsd-stable@FreeBSD.ORG Sun Oct 3 06:18:14 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 B505B106564A for ; Sun, 3 Oct 2010 06:18:14 +0000 (UTC) (envelope-from kamikaze@bsdforen.de) Received: from mail.bsdforen.de (bsdforen.de [212.204.60.79]) by mx1.freebsd.org (Postfix) with ESMTP id 763F68FC12 for ; Sun, 3 Oct 2010 06:18:14 +0000 (UTC) Received: from mobileKamikaze.norad (HSI-KBW-078-042-098-160.hsi3.kabel-badenwuerttemberg.de [78.42.98.160]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bsdforen.de (Postfix) with ESMTP id 3E8938A2866; Sun, 3 Oct 2010 08:18:13 +0200 (CEST) Message-ID: <4CA82024.8010503@bsdforen.de> Date: Sun, 03 Oct 2010 08:18:12 +0200 From: Dominic Fandrey User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-GB; rv:1.9.1.12) Gecko/20100918 Thunderbird/3.0.8 MIME-Version: 1.0 To: Miroslav Lachman <000.fbsd@quip.cz> References: <4CA78EE3.9020005@quip.cz> In-Reply-To: <4CA78EE3.9020005@quip.cz> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 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: Sun, 03 Oct 2010 06:18:14 -0000 On 02/10/2010 21:58, Miroslav Lachman wrote: > 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 You know that with this syntax FS="," is treated as a condition to run the following block in angle brackets? I.e. you assign FS for every line of input. What seems to have changed is when and how a variable assignment returns true or false in a boolean condition. Any way, I doubt it was your intention to conditionally execute the code, so this is a bug in your programming. The correct approach to do what you want to is the BEGIN block if you want to do it in the code. For your use of head, consider the following: > awk 'BEGIN {FS=","} NR <= 5 { print $1"-"$2 }' GeoIPCountryWhois.csv That way the code is executed under the condition that the line number is less or equal 5. -- A: Because it fouls the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?