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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, 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




Response Number 1
Name: WilliamRobertson
Date: October 1, 2003 at 16:11:27 Pacific
+1
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.


Reply to Message Icon

Related Posts

See More


partitioning files into c... csh question



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


Google Ads



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