awk oddity: 2.8BSD vs. ULTRIX

Jeff Forys forys at sunybcs.UUCP
Sun Sep 21 06:13:28 AEST 1986


> When I type this [edited] command:
>
>    awk '{ $1 = $2 + $3; print $0 }'
>    1 1 1 1
>
> I get these responses:
>    2 1 1 1                 on 2.8BSD on an 11/70, and
>    1 1 1 1                 on ULTRIX 32m v. 1.1 on a MicroVax II
>                            and on 4.2BSD on a Vax 780.
>
> Why does awk vary in its response?

It's just a bug in 4.2 awk and isn't dependant on machine type.
Since DEC wanted ULTRIX 1.1 identical to 4.2, they retained the bug.  :-)
I don't know who fixed it under 2.8, but it has also been fixed (well,
to this extent anyways) in 4.3.  You can, of course, do either:

	print $1, $2, $3, $4		# and the results will be correct

or, more portably (i usurped this from John Pierce's Supp. Doc for awk):

	output = $1			# Concatenate output fields
	for (i = 2; i <= NF; ++i)	# into a single output line
	    output = output OFS $i	# with OFS between fields.
	print output

I'll mail you a copy of the supplemental document for awk, Jeff.  If
anyone else wants one, send me mail (yeah I know, that was dumb ;-).
---
Jeff Forys @ SUNY/Buffalo Computer Science (716-636-3004)
Forys at Buffalo.CSNET  -or-  ..!{watmath|decvax|kitty}!sunybcs!forys



More information about the Comp.unix.wizards mailing list