The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 02:50 PM
Single line file editing command? gator76 Shell Programming and Scripting 1 04-03-2008 10:09 AM
run command Unix on a single line Riddick61 UNIX for Dummies Questions & Answers 8 02-04-2008 02:19 PM
single line command roshanjain2 Shell Programming and Scripting 4 02-07-2007 05:33 AM
getting rid of $ when entered at the command line bashirpopal Shell Programming and Scripting 2 04-04-2003 10:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
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
  #2 (permalink)  
Old 08-24-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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
  #3 (permalink)  
Old 08-24-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

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

should work too
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0