Showing results for 
Search instead for 
Do you mean 

awk help

Super Advisor

awk help


I am doing an awk on a file and getting the output as below, is there a way I can have spacing between $2 and $4 so that $4 is lined up symmetrically unlike what I am getting below?

awk -F: '{print $2"\t\t\t"$4}' filename

xxxxxxxxxxxxx 8581
xxx 8585
xxxxxx 8590
xxxx 8595
xxxxxxx 9400
xx 9510
xxxxxxxxxxxxxxx 9520

Honored Contributor

Re: awk help

>> symmetrically

Not sure anyone understand clearly what that means.
Terms folks tend to understand are columns and field and left of right aligned.


Use a PRINTF instead of PRINT
Use '%-?ns' for a left-aligned ?-columns wide string field.

For the second column ($4) you may want a %0?d formatting if you want to play with leading zeroes.

Read any C, AWK, PERL or SHell book or man-page for all the details.


For example, using your output as input:

$ awk '{printf ("%-20s%6s\n",$1,$2)}' x.x
Honored Contributor Honored Contributor

Re: awk help

yep, use printf
Support Fatherhood - Stop Family Law
Super Advisor

Re: awk help

The original awk statement worked for me once I redirected the output to xls file.