GNU bug report logs -
#17196
multibyte: printf: %s counts bytes instead of characters
Previous Next
Full log
Message #11 received at 17196 <at> debbugs.gnu.org (full text, mbox):
On 04/06/2014 11:15 AM, Pádraig Brady wrote:
> On 04/06/2014 12:17 AM, Jan Novak wrote:
>> Hello,
>>
>> printf string format counts bytes instead of chars, which leads to broken output ...
>> (the same problem occurs with bash built in printf)
>>
>>
>> just try this:
>>
>> $ echo $LANG
>> us_US.UTF-8
>>
>>
>> $ printf "|%3s|\n" "a"
>> | a|
>>
>> $ printf "|%3s|\n" "á" (char is a-acute)
>> | á|
>>
>> expected output:
>> | á|
>>
>> Is there some easy solution ?
>>
>> TIA for the answer
>
> Yes printf follows the C standard which only considers bytes.
> awk does respect characters in width specifiers though:
>
> $ awk 'BEGIN{printf "|%3s|\n", "á"}'
> | á|
Jan points out to me the the awk solution is not portable
to mawk 1.3.3 at least. I used GNU Awk 3.1.8 above.
Pádraig.
This bug report was last modified 6 years and 250 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.