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
Triml leading zeros in unix kingofprussia UNIX for Dummies Questions & Answers 7 08-07-2008 06:04 AM
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
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 Rating: Thread Rating: 1 votes, 2.00 average. Display Modes
  #1 (permalink)  
Old 06-17-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
Replacing leading zeros with leading spaces

Hi,
May i know how to replace the leading zeros with leading spaces.

eg:

Input
------
001235
000012
005655

Output
-------
1235
12
5655

Question 2:
How to transform the same output as follows

1235 *****
12 *****
5655 *****

Where *'s are some other value part of record.
The first field that requires the transformation is fixed say 6 digit as in this example('1235 ').
  #2 (permalink)  
Old 06-17-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
You ask about leading spaces but your example shows no leading spaces. Which do you want?
  #3 (permalink)  
Old 06-17-2008
Srik Srik is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
For question1 try this:

cat a.txt | sed " s/^0*//"
  #4 (permalink)  
Old 06-18-2008
ThobiasVakayil ThobiasVakayil is offline
Registered User
  
 

Join Date: May 2006
Posts: 64
awk '{printf("%6d\n",$1)}' <file.txt
  #5 (permalink)  
Old 06-18-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
Quote:
Originally Posted by Srik View Post
For question1 try this:

cat a.txt | sed " s/^0*//"
This will trim all the leading 0's. But my requirement is different.
  #6 (permalink)  
Old 06-18-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
Quote:
Originally Posted by fpmurphy View Post
You ask about leading spaces but your example shows no leading spaces. Which do you want?
Sorry copy paste error. The expected output is

Code:
Output
-------
   1235
     12
   5655
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 08:37 PM.


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