🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Henry Spencer Tue, 20 Mar 1984 03:06
V7 awk bug
#133
Author: Henry Spencer
Date: Tue, 20 Mar 1984 03:06
35 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads