Formatting digits

I want to check the argument in KSH. If the user type in the prompt 'find 3' it will format 3 to 003 to match the data in the text file. Same as with 10 to 010. Always begins with 0.

eg.

>find 3

Output:
003

>find 30
Output:
030

There is a utility with the name find, don't use the name find for your script.
You can use printf to format the data, something like this to print the 1st argument:

data=`printf "%03d" $1`

Regards

Sorry..'find' is just a sample, the actual name is 'findlog'.
Is printf works in ksh? I'm just a newbie. Thank you.

Yes, it should work in ksh.

Regards

I tried to test the below code but it is showing me odd results

data=`printf "%03d" $1`
echo $data

Sample test:
> findlog.sh 001
001
> findlog.sh 020
016
> findlog.sh 035
029
> findlog.sh 099
printf: 099: not completely converted
000

The 1 or 2 digits is ok but when the 3 digit is used which is the correct argument, it is showing wrong number. eg 035 should also result in 035. Thank you.

It's a strange behaviour of the built-in printf statement in ksh, try it with awk:

data=`echo $1 | awk '{printf "%03d", $0}'`
echo $data

Regards

ei..its working great! thank you so much.