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
Help needed in padding leading zeros jakSun8 Shell Programming and Scripting 12 07-02-2008 08:41 PM
Removing leading zeros from a variable toshidas2000 Shell Programming and Scripting 6 02-27-2008 01:13 PM
truncating leading zeros of a column in a file nvuradi Shell Programming and Scripting 7 08-30-2007 07:04 AM
how to retain leading zeros Manish Jha Shell Programming and Scripting 3 11-09-2006 05:59 PM
Leading zeros wtofu Shell Programming and Scripting 1 09-16-2006 03:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2007
kingofprussia kingofprussia is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
Triml leading zeros in unix

Hi All,

How does one trim leading zero's in unix

Thanks
KP.
  #2 (permalink)  
Old 03-30-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 611
One method...


Code:
x=00001230000
echo $x | sed 's/\([0]*\)\([1-9]*\)\([0-9]*\)/\2\3/'

Output:
1230000
  #3 (permalink)  
Old 03-30-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960

Code:
echo $x  | sed 's/^[0]*//'

  #4 (permalink)  
Old 03-30-2007
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
This?


Code:
$ cat smp.ksh
#!/bin/ksh
num=00000100
print $num
typeset -i num
print $num

$ ./smp.ksh
00000100
100
$

  #5 (permalink)  
Old 03-30-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
/db2home/training> x=000001111111
/db2home/training> x=${x##+(0)}
/db2home/training> echo $x
1111111

  #6 (permalink)  
Old 03-30-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 611
s=00001210000
s=$(echo $s | awk '{printf "%d\n",$0}')
echo $s
1210000
  #7 (permalink)  
Old 03-30-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558

Code:
# s=00001210000
# echo $s
00001210000
# echo $s |bc
1210000

Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

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 05:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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