Here is full code:
foreach my $file (@safiles) {
@sa_data = qx(/usr/sbin/sa -m $file);
foreach my $user (@cplist) {
push(@all, grep { /$user/ } @sa_data);
}
}
foreach my $user (@cplist) {
@data = grep { /$user/ } @all;
print @data;
print ".............\n";
}
I am looping through system acct data file & collecting lines for each system users and pushing it to an array called @all.
Then I am grepping each user on @all & sending it to @data array. If I print @data it shows each user's data in batches:
cp1556 1 0.01re 0.01cp 0avio 22336k
cp1556 1 0.01re 0.01cp 0avio 22336k
cp1556 63 862.28re 0.17cp 0avio 13839k
cp1556 43 176.03re 0.13cp 0avio 12083k
cp1556 40 653.49re 0.12cp 0avio 13258k
cp1556 30 506.61re 0.05cp 0avio 12177k
cp1556 4 0.02re 0.02cp 0avio 19736k
.............
cp1449 6 0.26re 0.11cp 0avio 30176k
cp1449 3 0.07re 0.04cp 0avio 30261k
cp1449 2 0.00re 0.00cp 0avio 17135k
Now I want to sum the columns here where output == cp1449 $2total, $3total, $4total etc
@datathen$data[0]would be your 1st cplist,$data[1]would be your 2nd cplist, so on.. Take out the$data[0]andsplitit withspaceand get the values from required column and sum it. You didn't show us the entire code like what are the values in@allarray? Edit the question and add your code.cp1449should look like this? -cp1449 11 0.33re 0.15cp 0avio 77572k