#!/usr/bin/perl use strict; use warnings; my $i = 0; my $mcpupct=0; my (%total, $total); for my $file ("PSAMARTst1.csv") { open (my $SORTED,"<",$file) or die "Can't open file $file: $!"; open (my $OUTCSV,">","PSAMARTst1out.csv") or die "Can't open OUT file: $!"; while (my $line = <$SORTED>) { chomp($line); $line =~ s/%//g; ## Remove % Signs so that Percentages can be Operated On next if $line =~ /^Server,Date/; my ($server,$date,$login,$appl,$cpumin,$cpupct) = (split(",",$line)); ## if ($. == 0) { ## print $OUTCSV "$server $date, \n"; ## print $OUTCSV " \n"; ## } $mcpupct += $cpupct; $total{$appl} += $cpupct; } foreach my $appl (sort keys %total) { printf $OUTCSV ("$appl,%3.1f%% \n", $total{$appl}); ## printf $OUTCSV ("$server,$date,$appl,%3.1f%% \n", $total{$appl}); } if (eof($SORTED)) { printf $OUTCSV ("TOTAL,%3.1f%% \n", $mcpupct); ## printf $OUTCSV ("$server,$date,TOTAL,%3.1f%% \n", $mcpupct); } close $SORTED or die "Can't close input SORTED file: $!"; close $OUTCSV or die "Can't close PSAMARTst1out.csv data file: $!"; } ########################################################## # # Sort PSAMARTst1out.csv # Descending by CPU Percentage # ########################################################## system("sort -t, -n -r -o PSASortTst2.dat +1 PSAMARTst1out.csv");