Date: Sun, 03 Oct 2010 08:18:12 +0200 From: Dominic Fandrey <kamikaze@bsdforen.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: <4CA82024.8010503@bsdforen.de> In-Reply-To: <4CA78EE3.9020005@quip.cz> References: <4CA78EE3.9020005@quip.cz>
next in thread | previous in thread | raw e-mail | index | archive | help
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?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4CA82024.8010503>