henry@utzoo.UUCP (Henry Spencer) (03/20/84)
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