Hi,
I have a variable... it can take a value from 1 to 99...
now when it is 1 to 9 i want to save it as 01 to 09 in the same variable... can this be done using sed or awk???
a=1
i want it as a=01
Thanks in advance...
Hi,
I have a variable... it can take a value from 1 to 99...
now when it is 1 to 9 i want to save it as 01 to 09 in the same variable... can this be done using sed or awk???
a=1
i want it as a=01
Thanks in advance...
a=$(printf "%02d" 1)
getting error as
sprintf: not found
I am using bash shell...
Try printf instead of sprintf
In ksh, you can do
typeset -Z2 a
You can try like...
for i in 0{1..9} {10..12}; do echo $i; done
Using seq:
for i in $(seq -w 1 99)
if [ $a -gt 0 -a $a -lt 10 ]
then
a="0$a"
fi
echo $a
My bad, sorry. I meant printf.