Article View: net.bugs.v7
Article #133V7 awk bug
From: Henry Spencer
Date: Tue, 20 Mar 1984 03:06
Date: Tue, 20 Mar 1984 03:06
35 lines
1757 bytes
1757 bytes
I just ran into an interesting bit of misbehavior by awk. I'm processing
a file which looks roughly like this:
private $1.00 3600 seconds
public $1.00 3600 seconds
dialup $2.00 3600 seconds
disk $1.00 1000 block-days
with the following awk program (stripped of some irrelevancies):
BEGIN { FS = "\t" ; OFS = "\t" }
/./{
n = split(substr($2, 2), dolcent, ".")
print n, $1, dolcent[1] dolcent[2], $3
}
We get rid of $ by taking the substr from the second character on, and
then split it and output the result. Guess what? For the very first
line in the file, the split yields n == 0 (!). The line itself is not
to blame: I tried reordering the lines, and the problem still appears
on the first and only the first. Inserting a trash line (which gets
kicked out by some earlier checking) in front doesn't affect the result.
Changing the "split(..." line to:
it = substr($2, 2)
n = split(it, dolcent, ".")
make the problem go away! For some reason split doesn't like having
a substr as its first argument... once!
I have not investigated the problem in depth, since I lack both the time
and the courage to go wading into awk. Any brave souls out there?
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henry
Technical Details
Message-ID:
<3664@utzoo.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!henryShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.bugs.v7,net.unix-wizards Subject: V7 awk bug Message-ID: <3664@utzoo.UUCP> Date: Mon, 19-Mar-84 22:06:53 EST Article-I.D.: utzoo.3664 Posted: Mon Mar 19 22:06:53 1984 Date-Received: Mon, 19-Mar-84 22:06:53 EST Organization: U of Toronto Zoology Lines: 35