1752328 Members
5993 Online
108786 Solutions
New Discussion юеВ

Re: awk help

 
Allanm
Super Advisor

awk help

Hi ALL,

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


Thanks,
Allan.
3 REPLIES 3
Hein van den Heuvel
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.

Anyway...

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.

Hein


For example, using your output as input:

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

Re: awk help

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

Re: awk help

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