Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sprintf zero padding

29 views
Skip to first unread message

Marc de Bourget

unread,
Aug 26, 2016, 4:55:34 PM8/26/16
to
BEGIN {
number = sprintf("%013.13s", "730003001000")
print number
}

MAWK (Klabaster version) and TAWK print "0730003001000",
while GAWK prints " 730003001000". Which one is correct?

Janis Papanagnou

unread,
Aug 26, 2016, 5:53:25 PM8/26/16
to
Both, since per standard it's undefined. (But Gawk's implementation makes
more sense, IMO. The shell builtins of ksh/bash/zsh behave similarly, BTW.
/usr/bin/printf complains about that conversion specifier combination in
context of %s, but not in context of %d.)

If your intention is to pad leading zeroes to numbers use %d instead of %s.

Janis

0 new messages