|
|
Question : Padding strings
|
|
How do I pad a variable such that it has 4 characters padded with zero
e.g. 1 become 0001 18 become 0018 567 become 0567 and 7677 stays as it is (dont need to wory about more than 4 characters)
Thanks
|
Answer : Padding strings
|
|
$ cat pad.ksh #!/bin/ksh var=18 printf "%04d\n" $var
var=567 printf "%04d\n" $var
var=7677 printf "%04d\n" $var
$ ./pad.ksh 0018 0567 7677
|
|
|
|
|