![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Retrieve the first 9 digits from the numeric value | sollins | Shell Programming and Scripting | 10 | 07-01-2008 04:19 AM |
| Digits display | Spoorthi16 | UNIX for Dummies Questions & Answers | 3 | 10-01-2007 08:26 PM |
| Only Digits as input | namishtiwari | UNIX for Dummies Questions & Answers | 2 | 08-21-2007 06:23 AM |
| How to cut last 10 digits off | psarava | Shell Programming and Scripting | 4 | 08-29-2006 03:52 AM |
| restrain the number of digits of a PID | mlefebvr | UNIX for Advanced & Expert Users | 1 | 05-27-2002 09:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
It's a strange behaviour of the built-in printf statement in ksh, try it with awk:
Code:
data=`echo $1 | awk '{printf "%03d", $0}'`
echo $data
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|