Operating System - HP-UX
1833882 Members
2138 Online
110063 Solutions
New Discussion

Text allignment, question.

 
SOLVED
Go to solution
rveri
Super Advisor

Text allignment, question.

Hi,
How to allign this text peroperly,
Please see the attachment,

Any script or command will help,

Thanks in advance,
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Text allignment, question.

Hi Rveri:

Use 'printf' (see the manpages). You can read your exiting data using a shell, 'awk' or Perl script.

Ascertain the number of columns in any line read and issue an appropriate 'printf' statement.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Text allignment, question.

Use this awk script to get you started:

my.awk
--------------------
{
if (NF == 7) {s1 = ""} else {s1 = $1}
printf("%-10.10s ",s1)
i = 2
while (i < NF)
{
printf("%-10.10s ",$i)
++i
}
printf("-10.10s\n",$NF)
}
--------------------------

Use it like this:

sar -d 2 5 | awk -f my.awk
or
awk -f my.awk myinputfile

This is not meant to be a finished script but it will be close. A better script would build the awk script "on the fly" or a heredocs so that the external awk script is not needed.
If it ain't broke, I can fix that.