gawk does not handle UTF-8 multibyte characters properly. Here's an
example:
$ cat example.txt
A Only_a_singlebyte_character_here_(UTF-8:_41)
Ö A_letter_which_takes_two_bytes_(UTF-8:_c3_96)
€ A_currency_symbol_which_takes_three_bytes_(UTF-8:_e2_82_ac)
$ cat example.txt | awk '{ printf "%-5s%s\n",$1, $2 }'
A Only_a_singlebyte_character_here_(UTF-8:_41)
Ö A_letter_which_takes_two_bytes_(UTF-8:_c3_96)
€ A_currency_symbol_which_takes_three_bytes_(UTF-8:_e2_82_ac)
As we can see the format specifier %-5s does not calculate field widths
correctly when string contains multibyte characters. Unfortunately this
makes gawk's field widths mostly unusable with UTF-8 locale.
clone 313411 -1 retitle -1 mawk: UTF-8 multibyte characters are not handled properly thanks /usr/bin/mawk seems to be default awk interpreter in Etch. The same UTF-8 bug is in mawk too.
Hi!
This bug is a show-stopper whenever one wants to set a field width with
the %s format specifier.
It has been reported quite some time ago and I cannot see any activity.
Can this bug at least be forwarded upstream, please?
BTW, I experienced this bug while trying to center lines of text inside
an 80-column container:
$ echo 'hello world' | awk '{ w = int((80 + length())/2); printf "%" w "s\n", $0; }'
hello world
$ echo 'hèllo wörld' | awk '{ w = int((80 + length())/2); printf "%" w "s\n", $0; }'
hèllo wörld
Do you happen to know of a command-line tool that can read text lines
from stdin and write them centered to stdout?
Thanks for any help.