bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] FIELDWIDTHS can miscount the number of fields


From: Nethox
Subject: Re: [bug-gawk] FIELDWIDTHS can miscount the number of fields
Date: Mon, 22 May 2017 06:31:32 +0200

2017-05-21T22-12-44+0300, Arnold Robbins:
> Q4. Given the idea that using "*" at the end of FIELDWIDTHS to mean
>     anything else, then with FIELDWIDTHS = "2 3 4 *", and input
>     data "aabbbccccdddd" the dddd would go into $4. The final data
>     would be optional.  Is there any reason not to add this to gawk?
>     It seems to be actually useful and not just theoretically useful.
>
> A4. Arnold thinks it's right to add it.

It is more meaningful for input validation. The user could invoke this
after setting FIELDWIDTHS:
function expected(        arr, i) {
    EXPECTEDNF = split(FIELDWIDTHS, arr, " ")
    if (arr[EXPECTEDNF] == "*") {
        delete arr[EXPECTEDNF--]
    }
    for (i in arr) {
        EXPECTEDLENGTH += arr[i]
    }
}
And then check length() - EXPECTEDLENGTH == 0 (>= 0 when using "*").

Additional details:
1) Given FIELDWIDTHS = "2 3 4 *" and input data "aabbbcccc", NF == 3?
2) Currently, gawk avoids letters and 0 in FIELDWIDTHS . You will
probably have to check that "*" is unique and at the end (or absent).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]