Search this Website

 

Ubuntu

UNIX

pad zeros

Category: UNIX-Unix Beginner

pad zeros

hi can i know command to pad zeros to a value

code:



code:

printf "%08d" 16[img]http://www.unix.com/images/buttons



sorry i should have specified it more clear...

i may also get numbers like this...

code:

16
116
1116

all these should be populated with leading zero's and length equal to 8
00000016
00000116
00001116



code:
a=16
typeset -z 8 a


then it should be this:

code:

printf "%0.8d" 1116
or if you prefer awk

code:

awk 'begin {printf("%0.8d\n", 1116)}'[img]http://www.unix.com/images/buttons



quote:
printf "%0.8d" 1116

should be

code:
printf "%0.8d\n" 1116[img]http://www.unix.com/images/buttons