[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] more on OFS
From: |
Nelson H. F. Beebe |
Subject: |
[bug-gawk] more on OFS |
Date: |
Fri, 10 Feb 2012 08:23:17 -0700 (MST) |
The reported problem with setting of OFS may be more subtle. Here is
a test script run on my system with current versions of three awk
implementations, and their side-by-side output:
% cat foo.sh
#! /bin/sh -
awktest()
{
echo a:b:c | $AWK -F":" '{$2="x"; OFS=FS; print}'
echo a:b:c | $AWK -F":" '{$2="x"; print; OFS=FS; print}'
echo a:b:c | $AWK -F":" '{$2="x"; print $1; OFS=FS; print}'
echo a:b:c | $AWK -F":" '{$2="x"; print; $2=$2; OFS=FS; print}'
}
AWK=gawk ; awktest > foo.gawk
AWK=mawk ; awktest > foo.mawk
AWK=nawk ; awktest > foo.nawk
Running the script produces three output files that can be viewed like
this, with my comments in a final column:
================================================
gawk mawk nawk comments
================================================
a:x:c a x c a:x:c 1 = 3, 2 differs
a x c a x c a x c 1 = 2 = 3
a x c a x c a x c 1 = 2 = 3
a a a 1 = 2 = 3
a:x:c a x c a:x:c 1 = 3, 2 differs
a x c a x c a x c 1 = 2 = 3
a:x:c a x c a:x:c 1 = 3, 2 differs
================================================
Thus, my latest gawk, and nawk (version 20110810) agree, but mawk
differs in 3 of the 7 lines. That suggests a gray area in the
language that hampers portability, and is perhaps best avoided.
Repeating the tests on about twenty platforms gave identical
results.
I then ran the test with 69 historical versions of gawk, back to 3.0.0
from 13-May-1996, and got identical output from all of them.
I personally rarely use OFS, in favor of using printf() to control my
output, but I agree that OFS can be useful for writing simple filters.
In any event, it would seem desirable to add some extra-vigorous tests
to the gawk test suite to ensure that the handling of OFS remains
stable, and in agreement with its documentation.
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- University of Utah FAX: +1 801 581 4148 -
- Department of Mathematics, 110 LCB Internet e-mail: address@hidden -
- 155 S 1400 E RM 233 address@hidden address@hidden -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug-gawk] more on OFS,
Nelson H. F. Beebe <=