Computing.Net > Forums > Unix > align fields in columns

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

align fields in columns

Reply to Message Icon

Name: yacob
Date: October 1, 2003 at 12:33:43 Pacific
OS: Lunix
CPU/Ram: 1ghz
Comment:

Hi Listers,

I have tens of files and each files has got
a number of records. There is only three
fields in each record. I would like to align
fields in columns.

Can any one show me how to do it using
script.

Thanx

Yacob



Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: October 1, 2003 at 16:11:27 Pacific
Reply:

Maybe something like:

awk '{printf "%-20s%-20s%-20s\n", $1, $2, $3}' yourfile.dat

"%...s" means a character string.

20 means a length of 20 characters.

awk defaults to right-alignment (presumably for columns of figures) so you need -20 for left-alignment.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: align fields in columns

unix: count unique fields in column www.computing.net/answers/unix/unix-count-unique-fields-in-column/7746.html

replacing fields in delimited file www.computing.net/answers/unix/replacing-fields-in-delimited-file/6463.html

Awk to edit field in file www.computing.net/answers/unix/awk-to-edit-field-in-file/8482.html