[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gawk printf misunderstand
From: |
Aharon Robbins |
Subject: |
Re: [bug-gawk] gawk printf misunderstand |
Date: |
Wed, 31 Oct 2012 21:43:53 +0200 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Greetings. Re this:
> Date: Wed, 31 Oct 2012 16:44:17 +0600
> From: 145 Shkerin Egor (PROG) <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] gawk printf misunderstand
>
> Hello,
> I have two different behavior in two neighbor versions,
> please clarify, what is wrong and how to make common solution.
>
> GNU Awk 3.1.5
> Copyright (C) 1989, 1991-2005 Free Software Foundation.
>
> echo "ff" | awk '{printf("% 4s\n", $1)}'
> ff
>
> echo "ff" | awk '{printf("%04s\n", $1)}'
> 00ff
>
> It works exactly as I expect.
>
> In the same time:
>
> GNU Awk 3.1.8
> Copyright (C) 1989, 1991-2010 Free Software Foundation.
>
> echo "ff" | awk '{printf("% 4s\n", $1)}'
> ff
>
> echo "ff" | awk '{printf("%04s\n", $1)}'
> ff
>
> WHY not 00ff?
> --
> Egor Shkerin
Please see this from the NEWS file:
> Changes from 3.1.7 to 3.1.8
> ---------------------------
> 1. The zero flag no longer applies to %c and %s; apparently the standards
> changed at some point.
So, the change was on purpose. You can build the string yourself, which
I admit is more work, but will be portable.
function zero_prefix(string, len)
{
while (length(string) < len)
string = "0" string
return string
}
Thanks,
Arnold