Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk formatting 1

Status
Not open for further replies.

Mag0007

MIS
Feb 15, 2005
829
US
Is it possible to get a stricter awk format with printf?

I am having problems if my %s is very large, and it messes up my whole line.

for example I have something like this.

printf("%s\t\t\t%s*%s"megabytes"\t\t\t\t%d \n",$3,$27,$12,$27*$12)

TIA!
 
To lilit to 70 chars: %-70.70s

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
thanks for the reply PHV.

I guess i am looking more for a spredsheet type solution on my cells.

I am trying to build a table, but values are keep getting mangles because some fields are large and some are small. I need consistency :)
 
The %-X.Xs format force the width to exactly X characters.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV:

Hmm I am trying it...
I was playing with that, and now I think I think what the issue is.

printf("%.11s \t\t\t\t\t %.4s * %.4s \t\t\t\t %8.0f \n",$3,$27,$12,$27*$12)

The $3 variable max size gets to be 11, so I capped it off at 11, but I can't seem to control $27, $12 and $27*$12 to be in the same place...

 
And this ?
printf("%-11.11s \t\t\t\t\t %-4.4s * %-4.4s \t\t\t\t %8.0f \n",$3,$27,$12,$27*$12)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top