I need to pad 0 to a number on the right. to make it 9 digit in total.
My number is 2457
output should be 245700000
I need to pad 0 to a number on the right. to make it 9 digit in total.
My number is 2457
output should be 245700000
One way in Bash could be:
n=$(printf "%-9s" 2457)
printf "%s\n" ${n// /0}
245700000
Or
printf "%s%0*d\n" ${X} $((9-${#X})) 0
245700000
printf "%s%0$((9-${#X}))d\n" ${X}
245700000
The latter suggestion is portable.
Once defined as a function it becomes handy:
rightpad0() { printf "%s%0$((${1}-${#2}))d\n" "${2}"; }
rightpad0 9 2457
245700000