![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
Quote:
Code:
fmt -w 41 file |
|
#4
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |