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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with formatting using awk 1

Status
Not open for further replies.

SSG1

Programmer
Jan 17, 2002
48
US
Hi,
I am trying to make the output of sar on an HP-UX uniprocessor box to be the same as that from a multiprocessor box by adding a dummy column. And I was trying do this using awk. However, I am not getting the expected output.

sar -u -M 2 2
Here is the output on multiprocessor boxes:
11:23:02 cpu %usr %sys %wio %idle
11:23:04 0 0 0 0 100
1 0 5 0 95
2 0 0 0 100
3 0 0 0 100
system 0 1 0 99

Here is the output on uniprocessor box:
12:51:32 %usr %sys %wio %idle
12:51:34 0 0 0 100
12:51:36 0 0 0 100

Average 0 0 0 100

I need to add a dummy cpu column with all 0's in it while preserving the field separators etc in the input.

can anyone tell me the best way to handle this ?

Thanks
 
Hi:

If it were me, I'd use the formatting printf statement of awk to get the proper spacing. Assuming data.file is the output of your sar report.

You'll probably have to set the spacing to your liking:

awk ' {
if(NR == 1) # field 1 has the heading
{
printf("%s cpu %s %s %s %s\n", $1, $2, $3, $4, $5)
continue
}

if(NF > 1)
printf("%s 0 %3s %3s %3s %3s\n", $1, $2, $3, $4, $5)
else
print # the blank line
} ' data.file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top