- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need to learn how to calculate averages for script...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 08:02 PM
тАО09-22-2008 08:02 PM
c39t1d1 10.1
c39t1d1 10.7
c39t1d1 11.0
c39t1d4 10.6
c39t1d4 10.8
c39t1d7 11.1
c39t1d7 11.4
c39t1d7 11.5
c39t1d7 16.3
c40t1d3 10.0
c40t1d3 10.1
c40t1d3 10.2
c40t1d3 10.2
c40t1d3 10.3
c40t1d3 10.1
I am not able to figure out how to calculate averages for each cXtXdX. Can somebody help a
newbie?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 08:35 PM
тАО09-22-2008 08:35 PM
Solutionsort sar_data | awk '
BEGIN { getline; disk=$1; sum=$2; count=1 }
{
if ($1 == disk) {
sum += $2
++count
} else {
print disk, sum / count
disk=$1; sum=$2; count=1
}
}
END { print disk, sum / count } '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 08:45 PM
тАО09-22-2008 08:45 PM
Re: Need to learn how to calculate averages for scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 09:09 PM
тАО09-22-2008 09:09 PM
Re: Need to learn how to calculate averages for scripting
If you want to take the average of all data
so here is the solution:
awk '{ print $2}'
ln=`wc -l tmp1.out| awk '{print $1}'`
if test $ln -ne 0
then
tot=0
for i in `cat tmp1.out`
do
tot=`echo $tot + $i | bc -l`
done
avg=`echo $tot / $ln | bc -l`
fi
printf "SAR : %.2f\n" $avg
rm tmp1.out
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-24-2008 10:02 PM
тАО09-24-2008 10:02 PM
Re: Need to learn how to calculate averages for scripting
awk handles that too:
awk '
{
sum += $2
}
END { print sum / NR } ' sar_data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-25-2008 04:28 AM
тАО09-25-2008 04:28 AM
Re: Need to learn how to calculate averages for scripting
Really it is a nice code.
Suraj