From owner-freebsd-hackers Thu Mar 6 12:35:36 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id MAA09902 for hackers-outgoing; Thu, 6 Mar 1997 12:35:36 -0800 (PST) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id MAA09895 for ; Thu, 6 Mar 1997 12:35:18 -0800 (PST) Received: (from uucp@localhost) by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id VAA15063; Thu, 6 Mar 1997 21:35:11 +0100 Received: (from j@localhost) by uriah.heep.sax.de (8.8.5/8.8.5) id VAA15093; Thu, 6 Mar 1997 21:18:02 +0100 (MET) Message-ID: <19970306211802.CZ51686@uriah.heep.sax.de> Date: Thu, 6 Mar 1997 21:18:02 +0100 From: j@uriah.heep.sax.de (J Wunsch) To: spaz@u.washington.edu (John Utz) Cc: hackers@FreeBSD.ORG Subject: Re: awk bug? in 2.2 BETA? References: X-Mailer: Mutt 0.60_p2-3,5,8-9 Mime-Version: 1.0 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: ; from John Utz on Mar 6, 1997 10:23:34 -0800 Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk As John Utz wrote: > mira: {60} cat fd1.dat | awk 'BEGIN { FS = " " }; END { printf "rf= %g; cf > = %g\n;", NR, NF }' > > rf= 9801; cf = 0; > > cf should be 3! > > fd1.dat has 9801 lines and 3 colums of data, and this awk is not reporting > the columns.... NF The number of fields in the current record. Inside a BEGIN action, the use of NF is undefined unless a getline function without a var argument is executed previously. Inside an END action, NF shall retain the value it had for ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the last record read, unless a subsequent, redirected, ^^^^^^^^^^^^^^^^^^^^ getline function without a var argument is performed prior to entering the END action. Our version of awk breaks this. It resets NF to 0 before the EOF is seen. -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)