bug-gawk
[Top][All Lists]
Advanced

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

Re: gawk - printf discards field-width when space modifier used [SOLVED]


From: David C. Rankin
Subject: Re: gawk - printf discards field-width when space modifier used [SOLVED]
Date: Sat, 8 Jan 2022 13:58:26 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1

On 1/8/22 9:40 AM, Ed Morton wrote:
>        printf j ? " % 4d%s" : "% 4d%s", rv, (j<cols-1) ? "" : ORS > "file.txt"

Ed, All,

  I apologize. I was suffering from a momentary CRI. This can be closed. I was
short by 1 on my field-width thinking the space-modifier provided the
additional space before the specified field-width for the minus sign instead
of the space being reserved out of the specified field-width.

(a field-width of 5 was needed instead of 4)

  So:

printf (j) ? " % 5d%s" : "% 5d%s", rv, (j<cols-1) ? "" : ORS > "file.txt"

  works just fine, or more appropriately as Ed suggested:

printf (j ? " % 5d%s" : "% 5d%s"), rv, ((j<cols-1) ? "" : ORS) > "file.txt"

  So, hat-in-hand, this can be closed.

(CRI - cranal-rectal inversion, e.g. head up my ...)

-- 
David C. Rankin, J.D.,P.E.



reply via email to

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