[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk - printf discards field-width when space modifier used
From: |
David C. Rankin |
Subject: |
Re: gawk - printf discards field-width when space modifier used |
Date: |
Sat, 8 Jan 2022 13:07:28 -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:
> Actually - I'm not sure how this series of ternary expressions gets
> interpreted:
>
> printf j ? " % 4d%s" : "% 4d%s", rv, (j<cols-1) ? "" : ORS > "file.txt"
>
> but when I just add parens to make it more readable and express what I think
> is your intent:
>
> printf (j ? " %4d%s" : "%4d%s"), rv, (j<cols-1 ? "" : ORS)
Thank you Ed,
Not quite the same. I need both the "space modifier" so that either the
negative sign or space is provided and the "field-width" for alignment when
generating values between -5000 and 5000 for example.
e.g.
$ sh randvaluegen.sh 10 10 -5000 5000
Using either the "space modifier" or "field-width" alone and the format is
fine, e.g.
"% d" or "%4d"
but when both are used:
"% 4d"
One or more of the field-width size is discarded.
(and yes, good call, I'll pair down the example with another test, I thought
the 10 or so lines were fairly minimal -- but it should be more minimal in
hindsight)
--
David C. Rankin, J.D.,P.E.