i would like to format the 9 character with suffix as "0".
i tried below it doesn't work.
>a=12345
> echo $a | awk '{printf "%-09s\n",$1}'
>12345
required output is 123450000
can you guys help me out ?
i would like to format the 9 character with suffix as "0".
i tried below it doesn't work.
>a=12345
> echo $a | awk '{printf "%-09s\n",$1}'
>12345
required output is 123450000
can you guys help me out ?
Like this?
echo $a | awk '{ if(length($0)<9) print $0 "0000";else print $0 }'
I assume you want output string length 9.
i am sorry . I forgot to mention that "a" will be of variable length 1-9 characters.
Please see the updated code.
otherwise, post sample input & output data.
input
1
12
123
1234
12345
123456
1234567
12345678
123456789
required output
100000000
120000000
123000000
123400000
123450000
123456000
123456700
123456780
123456789
echo $a | awk '{printf("%9.9s\n", $1 "00000000")}'
or with your latest example:
awk '{printf("%9.9s\n", $1 "00000000")}' input
thanks a lot guys.
it worked out
Just in case you needed the values to do some further calculations, try
awk '{print $1*10^(8-int(log($1)/log(10)))}' file
100000000
120000000
123000000
123400000
123450000
123456000
123456700
123456780
123456789