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
Byte Padding naan High Level Programming 6 02-22-2007 02:09 AM
Padding variables flounder High Level Programming 1 09-05-2006 09:11 AM
Padding vijaygopalsk UNIX for Dummies Questions & Answers 2 06-27-2003 07:51 AM
Zero Padding to a string Wing m. Cheng High Level Programming 3 09-16-2002 06:58 PM
Padding issues informshilpa UNIX for Advanced & Expert Users 2 03-01-2002 10:51 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2008
Registered User
 

Join Date: Jul 2006
Posts: 29
Padding in Unix

I have a file with different character counts on each line
how do i make it with unique character counts.

example:

1st line : ABCD 011 XYZ 0000 YYYY BBB TEADINGDA
2nd line: ABCD 011 xys 0010 YYYY BBB TEAD
3rd line : ABCD 022 YXU 000 UUU BBB TE

1st line is 43 characters
2nd line is 39 characters
3rd line is 37 characters

how do i make all line to be 41 characters

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-22-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
I think we need more information.
For example, you could pad the lines with spaces at the end or the front.
Another choice is to expand the column width for each column to some max size, padding each column to that size.

What result do you need?
This pads spaces at the end:
Code:
awk '{ printf("%-41s", $0) }' filename > tmpfile
mv tmpfile filename
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 570
Quote:
Originally Posted by rudoraj View Post
I have a file with different character counts on each line
how do i make it with unique character counts.

example:

1st line : ABCD 011 XYZ 0000 YYYY BBB TEADINGDA
2nd line: ABCD 011 xys 0010 YYYY BBB TEAD
3rd line : ABCD 022 YXU 000 UUU BBB TE

1st line is 43 characters
2nd line is 39 characters
3rd line is 37 characters

how do i make all line to be 41 characters

Thanks
Code:
fmt -w 41 file
Reply With Quote
  #4  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 5
Above two suggestions are good and solve the question specifically, but if you need a variation with your end-of-line characters (like a zero or other strings), then this is conceptually simple and modifiable

cat filename | sed -e 's/$/random chars spaces numbers etc/' | cut -c1-41

Replace "random chars spaces numbers etc" with spaces/phrases/etc
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:56 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