#572138 mawk: Please add a function wrapping wcswidth()

Package:
mawk
Source:
mawk
Description:
Pattern scanning and text processing language
Submitter:
Teemu Likonen
Date:
2010-03-01 20:12:12 UTC
Severity:
wishlist
#572138#5
Date:
2005-06-13 14:42:48 UTC
From:
To:
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.

#572138#14
Date:
2006-12-29 21:55:30 UTC
From:
To:
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.

#572138#27
Date:
2008-09-18 21:49:27 UTC
From:
To:
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.