It is currently Sat, 04 Dec 2021 18:44:04 GMT



 
Author Message
 padding a field
Hi.  I'm looking for a command that will pad out a field in a file so
they have a fixed length.  I want to do this first to a couple
individual files and then join them.

file1
asd;lfa;slk
kjsda;lkgsdlkajfl
kjsdlkfd
lkjsdafljs;dlfj

file2
llkjsdfl
lksdjl
lskdjalf;lkj;asdjflksdaf
;lsjdf'kls'dalksda

I want file3 to look like..

asd;lfa;slk                 llkjsdfl
kjsda;lkgsdlkajfl        lksdjl
kjsdlkfd                     lskdjalf;lkj;asdjflksdaf
lkjsdafljs;dlfj               ;lsjdf'kls'dalksda

thanks in advance,
tony



 Sun, 20 Jul 2003 04:23:39 GMT   
 padding a field
In article <3a7721de.12975...@news.dal.ca>,

Most systems these days have a "printf" shell command that can be used for
this.

Is the right column supposed to be lined up vertically?  If you're trying
to show an example of fixed-length fields, don't use variable-width fonts
in your mailer!

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Sun, 20 Jul 2003 05:49:53 GMT   
 padding a field

If you know the maximum size of the field.
Say it is 40 characters;

sed 's/$/#SPC/' file1.in|sed 's/\(.\{#FIELD\}\).*/\1/'|paste - file2.in>file.out

You must subsitute ;
#SPC   =40 space characters (or n space characters where n is the maximum field width)
#FIELD ="40" (the field width, or any value you choose)

ie:
sed 's/$/                                        /' file1.in|sed 's/\(.\{40\}\).*/\1/'|paste - file2.in>file.out

file1.in= first input file (file1 above)
file2.in= second input file (file2 above)
file.out= resultant output file (file3 above)

Bye,

01001100



 Sun, 20 Jul 2003 23:40:10 GMT   
 
   [ 3 post ] 

Similar Threads

1. Padding a Field

2. printf to pad with spaces BUT trips over when data being padded contains spaces

3. Help - sending with mailx to bcc field instead of to: field

4. Using awk or cut to print every field after the 11th field

5. Think Pad install & mount points/partitions

6. Linux on IBM 71M Think pad

7. setup for psx pad usb adapter

8. keyboard number pad not working

9. Linux RedHat 6.1 on a Think Pad 570 with Etherjet Card

10. Light pad drivers


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software