jwp@uwmacc.UUCP (Jeffrey W Percival) (09/18/86)
Here's a curiosity I hope someone can help me on. I have a file called "cmd" with this line: { $1 = $2 + $3 } { print $0 } and a file called "data" with this line: 1 1 1 1 When I type this command: awk -f cmd data 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? -- Jeff Percival ...!uwvax!uwmacc!sal70!jwp or ...!uwmacc!jwp
forys@sunybcs.UUCP (Jeff Forys) (09/20/86)
> 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@Buffalo.CSNET -or- ..!{watmath|decvax|kitty}!sunybcs!forys
dph@lanl.ARPA (David P Huelsbeck) (09/22/86)
In article <268@uwmacc.UUCP> jwp@uwmacc.UUCP (Jeffrey W Percival) writes: >Here's a curiosity I hope someone can help me on. >I have a file called "cmd" with this line: > > { $1 = $2 + $3 } { print $0 } > >and a file called "data" with this line: > > 1 1 1 1 > >When I type this command: > > awk -f cmd data > >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? >-- > Jeff Percival ...!uwvax!uwmacc!sal70!jwp or ...!uwmacc!jwp Because awk under 4.2 is broken and ULTRIX works too much the same. This is fixed in 4.3 and SysV. dph@lanl.arpa
guy@sun.uucp (Guy Harris) (09/22/86)
> Because awk under 4.2 is broken and ULTRIX works too much the same. > This is fixed in 4.3 and SysV. More precisely, this is fixed in 4.3, and was never broken in other versions of UNIX. A fix for the 4.2 version was sent out a long while ago. -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)