The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ls command output in single line arsheshadri AIX 7 04-28-2008 11:50 AM
Single line file editing command? gator76 Shell Programming and Scripting 1 04-03-2008 07:09 AM
run command Unix on a single line Riddick61 UNIX for Dummies Questions & Answers 8 02-04-2008 10:19 AM
single line command roshanjain2 Shell Programming and Scripting 4 02-07-2007 01:33 AM
getting rid of $ when entered at the command line bashirpopal Shell Programming and Scripting 2 04-04-2003 07:41 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-24-2007
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
Append 0 for single digit entered from command line

I have a script like this--

#!/bin/ksh
echo "To pad a 0 before digits from 1-9"
for i in $*
do
echo $i | sed 's/[1-9]/'0[1-9]'/g'
done

I run this script as

ksh name 1 2 23 34

The output should be
01 02 23 34

Help me in modifying this script.

Thanks
Namish
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-24-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
#!/bin/ksh
echo "To pad a 0 before digits from 1-9"
for i in $*
do
   printf "%02s\n" $i
done
Reply With Quote
  #3 (permalink)  
Old 08-24-2007
Registered User
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 204
Code:
#!/usr/bin/ksh
echo $* | sed 's/ \|^/  /g ; s/[^1-9]\([1-9]\)[^1-9]/ 0\1 /g; s/  / /g'

should work too
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0