There are 4 fields in this input data. I want to get the average value for the column 2/3/4th. If you notice, disk c53t2d6 and c12t10d4 occured twice..so i need to get an average for them. If it occured only once, then just get take it as an average.
c42t3d0 0.01 0.00 1.19
c53t2d6 2.00 3.4 1.76
c12t10d4 0.01 0.00 1.42
c53t2d6 0.03 0.00 0.59
c12t10d4 0.02 0.00 0.82
THanks in advance. I been banging my head for a 3 days now..but no luck..Don't know how to structure it..
Jewsco
12 4233 numberwhun 3,509
Recognized Expert Moderator Specialist
That's all well and good, but what code have you produced? We need to see what you have tried before we can help you with it.
Regards,
Jeff
Ganon11 3,652
Recognized Expert Specialist
I'm thinking a hash, with the cXXXXX string as the key and an array reference as the value, with the array containing the numbers following it. Calculating the average, then, is fairly easy. It'll take some tweaking, but I'm sure you can do it.
KevinADC 4,059
Recognized Expert Specialist
I'm thinking a hash, with the cXXXXX string as the key and an array reference as the value, with the array containing the numbers following it. Calculating the average, then, is fairly easy. It'll take some tweaking, but I'm sure you can do it.
I agree.
here is the code, actually, its just opening and puting it into a hash. I stoped because i not sure how to proceed.. - open(SAROUT,"/tmp/input_file" ) or die "Can't open $!";
-
-
while(<SAROUT>) {
-
chomp;
-
s/\s+/ /g; s/^\s+//g;
-
$Lines++;
-
-
if ( $FoundBegin eq 1 ) {
-
print "Lines in between: $_\n";
-
( $Disk, $DiskBusy, $Avque, $Rws, $Blks, $DiskWaitIO, $DiskSvcTime ) = split / /, $_;
-
$Disks{$Lines}{'disk'}=$Disk;
-
$Disks{$Lines}{'busy'}=$DiskBusy;
-
$Disks{$Lines}{'waitio'}=$DiskWaitIO;
-
$Disks{$Lines}{'svctime'}=$DiskSvcTime;
-
-
}
-
-
if ( /$BeginTime/ ) {
-
$Lines=0;
-
print "Begin Line: $_\n";
-
( $SarTime, $Disk, $DiskBusy, $Avque, $Rws, $Blks, $DiskWaitIO, $DiskSvcTime ) = split / /, $_;
-
$Disks{$Lines}{'disk'}=$Disk;
-
$Disks{$Lines}{'busy'}=$DiskBusy;
-
$Disks{$Lines}{'waitio'}=$DiskWaitIO;
-
$Disks{$Lines}{'svctime'}=$DiskSvcTime;
-
$FoundBegin=1;
-
-
-
} elsif ( /$EndTime/ ) {
-
$Entries[$Lines]=$_;
-
print "End Line: $Lines\n";
-
close(SAROUT);
-
}
KevinADC 4,059
Recognized Expert Specialist
That code seems to have no relation to the data you posted previoulsy:
c42t3d0 0.01 0.00 1.19
c53t2d6 2.00 3.4 1.76
c12t10d4 0.01 0.00 1.42
c53t2d6 0.03 0.00 0.59
c12t10d4 0.02 0.00 0.82
Your code splits the lines into 8 fields of data, but the data you posted only has 4 fields (assumes space delimited). So whats wrong? The code or the data?
sorry for confusion..replace the open with..The begin and End pattern is 00:10:00 and 00:20:00 for example.. - open(SAROUT,"/usr/bin/sar -d -f $SarFile |" ) or die "Can't open $!";
output will be like
HP-UX cmihx195 B.11.23 U ia64 10/12/08 - 00:00:00 device %busy avque r+w/s blks/s avwait avserv
-
00:10:00 c2t6d0 10.85 1.43 31 755 1.90 9.74
-
c6t6d0 8.75 1.51 26 622 1.94 8.71
-
c8t12d7 0.01 0.50 0 0 0.00 2.25
-
c9t8d2 0.03 0.50 0 4 0.00 3.46
-
c9t0d1 0.14 0.50 0 23 0.00 7.60
-
c12t1d0 8.91 0.50 6 90 0.00 16.29
-
c12t1d1 12.21 0.50 6 103 0.00 19.11
-
c12t1d7 0.00 0.50 0 0 0.00 0.85
-
c12t1d2 11.73 0.50 6 98 0.00 19.28
-
c12t2d1 0.08 0.50 0 10 0.00 16.39
-
c12t2d0 0.09 0.50 0 14 0.00 26.69
-
c12t2d5 0.12 0.50 0 14 0.00 19.99
-
00:20:00 c2t6d0 6.20 0.69 14 151 0.56 9.50
-
c6t6d0 4.82 0.73 12 144 0.68 7.54
-
c8t12d7 0.01 0.50 0 0 0.00 3.03
-
c9t8d2 0.03 0.50 0 4 0.00 2.48
-
c9t0d1 0.02 0.50 0 1 0.00 1.54
-
c12t1d0 7.55 0.50 5 72 0.00 16.72
-
c12t1d1 8.59 0.50 5 73 0.00 18.82
-
c12t1d2 10.49 0.50 6 91 0.00 18.56
-
c12t2d1 0.00 0.50 0 0 0.00 1.18
Thansk a lot!
numberwhun 3,509
Recognized Expert Moderator Specialist
Twice you have posted code, and twice we have added code tags for you. Please be mindful of your posting and add code tags around any and all code. They are easy to use and quite necessary.
Regards,
Jeff
KevinADC 4,059
Recognized Expert Specialist
You're making it too hard. Maybe someone else will take the time to try and figure out what you want.
if you notice my first question, i made it simple actually. get the average for each occurence of disks. i didn't want to put the code as it may confuse you.. but somebody asked for it..
making it hard? yes its easy for you...thats the reason i asked your help in the forum..because i don't know how to make it work..
thanks,
jewsco
KevinADC 4,059
Recognized Expert Specialist
OK, sticking with your original sample data and assuming each field is averaged seperately: -
#use Data::Dumper;
-
my %HoA = ();
-
while (<DATA>){
-
chomp;
-
my @data = split(/\s+/);
-
for my $i (1..3){
-
$HoA{$data[0]}[$i-1]+=$data[$i];
-
}
-
$HoA{$data[0]}[3]++;
-
}
-
#print Dumper \%HoA;
-
foreach my $key (keys %HoA) {
-
print "Average for $key: ";
-
foreach my $i ( 0..$#{$HoA{$key}}-1 ) {
-
if ($HoA{$key}[$i] == 0) {
-
print "0 ";
-
}
-
else {
-
my $s = sprintf "%.4f", $HoA{$key}[$i] / $HoA{$key}[3];
-
print "$s ";
-
}
-
}
-
print "\n";
-
}
-
__DATA__
-
c42t3d0 0.01 0.00 1.19
-
c53t2d6 2.00 3.4 1.76
-
c12t10d4 0.01 0.00 1.42
-
c53t2d6 0.03 0.00 0.59
-
c12t10d4 0.02 0.00 0.82
-
This could be done a number of different ways so I am not in anyway suggesting my code is the best way to go about this. Hopefully it helps you extrapolate something you can apply to your real data and your needs.
Regards,
Kevin
WOW! Thank you very much Kevin! Appreciate it man..
I didn't know this technique. -
-
-
$HoA{$data[0]}[$i-1]+=$data[$i];
-
-
KevinADC 4,059
Recognized Expert Specialist
You're welcome. I hope it helps.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mavis |
last post by:
Hi,
I'm trying to use a simple form to select by which column I will display
output from a MySQL database.
I'd like to display based on ORDER BY and select Written, Average, etc.
I know the...
|
by: Aaron |
last post by:
I'm trying to get an average of a long and a std::vector::size_type, but keep
getting 0 for some reason.
I've tried the following:
float avg = some_long / some_vec.size();
float avg =...
|
by: Gary |
last post by:
Hi, I have a temperature conversion program down pat, but I was told to
add an average, meaning, i need to get the average temperature for as
many times as it was entered. i do not know where to...
|
by: C++Geek |
last post by:
I need to get this program to average the salaries. What am I doing
wrong?
//Program to read in employee data and calculate the average salaries
of the emplyees.
|
by: patelxxx |
last post by:
PERL Code to Ping a server:
#!c:/Perl/bin/perl.exe
use Net::Ping;
use strict;
use warnings;
my $host = 192.168.0.1; # Real value removed by MODERATOR
| |
by: jonniethecodeprince |
last post by:
Hello all. I need to get a html page to work with a PERL script
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"...
|
by: miguelguerin |
last post by:
Im having trouble getting the input from one file to another.
Main file:
package assigment3;
/**
*
* @author mguer017
*/
public class Main {
|
by: kumarboston |
last post by:
Hi All,
I am trying to get an average value for my data, here is my data file
DATA FILE
EP1934.PDB 250 250 11.27
EP1934.PDB 251 251 12.7332
EP1934.PDB 252 252 6.38341
EP1934.PDB 253 253...
|
by: kumarboston |
last post by:
Hi all,
I was trying to calculate the average value from different parts of the same data file. For example, if suppose we have number 1 - 10 and i was trying to calculate the average of only first...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |