Name: Hugo Date: April 30, 2008 at 13:57:44 Pacific Subject: nawk or sed help OS: Sol 9 CPU/Ram: 4GB Model/Manufacturer: v240
Comment:
Hi, I've written a one line script to consolidate ping stats for each device being pinged from a list of 30 devices. I am using a for-do loop and extracting and formatting the values. But I'm having problems extracting just the average value:
My output so far looks like this:
MyCity to device.domain.com (10.10.10.12): 04-30-08 13:05:00 min/avg/max = 103/106/113
I need it to show only the average value, like this: MyCity to device.domain.com (10.10.10.12): 04-30-08 13:05:00 avg = 106
How can I accomplist this since the value average is not always 3 characters? I tried using nawk and sed, but no luck yet extracting just the average for each ping result.
It's a kludge and it's easily broken if the data structure varies from what you've said.
Using a field seperator, FS, equal "/", then field 3 should be replaced by an equal sign and field 5 should be nulled out. That leaves the "min" string which is removed by a call to gsub.
maybe i misinterpreted what OP wants. I thought he meant to take the average of the 3 numbers. So its the middle number he wants..therefore, the for loop should be removed, and a[2] will be the average nnumber... thanks for pointing out
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE