The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Fill the Key fields : Please help us charandevu Shell Programming and Scripting 11 04-08-2008 06:40 AM
Find fields with no spaces in value alfredo123 UNIX for Dummies Questions & Answers 10 04-18-2007 03:14 PM
How can i remove spaces in between the fields in a file dsravan Shell Programming and Scripting 3 09-26-2006 01:11 PM
Align Text from a file. earlepps UNIX for Dummies Questions & Answers 9 08-01-2006 05:37 AM
Delete spaces in between fields guiguy Shell Programming and Scripting 12 03-31-2006 06:38 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-18-2005
Registered User
 

Join Date: May 2005
Posts: 48
align several fields and fill spaces with zero

hi all,

i have a big problem, and i donīt know what to do.
i have a flat file with several fields, which are separated by ";" like this:

5656838-7B;97030000-7;*;V16106133 ;1;1;
4612062-0B;97030000-7;*;C14038149 ;1;2;
8044938-0B;97030000-7;*;V16034219 ;1;2;

where B is a blank space.

each line is a record, and all have the same length. and each field has its determinated length. Example: field1[10],field2[10],field3[1],
field4[1],field5[8], ...

what i need, is align the content of the field 1 and 2 to the rigth, and put a zero to its left, like this:

05656838-7;97030000-7;*;V16106133 ;1;1;
04612062-0;97030000-7;*;C14038149 ;1;2;
08044938-0;97030000-7;*;V16034219 ;1;2;

is that possible??
please, any idea
thanks
Reply With Quote
Forum Sponsor
  #2  
Old 11-19-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
hasn't it already been answered here?

seems very similar to me......
Reply With Quote
  #3  
Old 11-23-2005
Registered User
 

Join Date: Sep 2005
Location: Chennai
Posts: 80
Another way:

cut -c1-9 filename >temp1
cut -c11- filename>temp2
paste -d"\0" temp1 temp2|sed 's/^/0/g'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:03 AM.


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

Content Relevant URLs by vBSEO 3.2.0