#!/user/bin/perl use strict; use warnings; use Scalar::Util::Numeric qw(:all); my %servers = ( 'cihcrppmon02'=>['standard_unix_corp-cis_shared',1703995999752,133635610485,31055995112,12.75,54.8,'ghnbu','gh_nbu02'], 'ovpip02' =>['standard_unix_corp-cis_shared',41851038572,14933570508,3835386732,2.80,10.91,'ghnbu','gh_nbu02'], ); my @input = ( "cihcrppmon02,standard_unix_corp-cis_shared,1703995999752,133635610485,31055995112,12.75,54.8, ghnbu, gh_nbu02\n", "ovpip02,standard_unix_corp-cis_shared,41851038572,14933570508,3835386732,2.80,10.91,ghnbu, gh_nbu02\n", "cihcispapp247,standard_unix_corp-cis_shared,190635017908,24806407611,9442867181,7.68,20.19,ghnbu, gh_nbu02\n", "wavmd003,standard_unix_corp-cis_shared,2760141244,594115253,299382152,4.65,9.22,ghnbu, gh_nbu02\n", ); foreach my $line_in (@input){ chomp($line_in); my @line = split(/,/,$line_in); my $name = shift @line; if(exists $servers{$name}){ foreach my $index (0..$#line){ if(isnum($line[$index]) && isnum($servers{$name}[$index])){ $servers{$name}[$index] += $line[$index]; } } } else { $servers{$name} = [@line]; } } foreach my $name (keys %servers){ print "$name: " . join(" ",@{$servers{$name}}) . "\n"; } exit(0); #### cihcrppmon02: standard_unix_corp-cis_shared 3407991999504 267271220970 62111990224 25.5 109.6 ghnbu gh_nbu02 ovpip02: standard_unix_corp-cis_shared 83702077144 29867141016 7670773464 5.6 21.82 ghnbu gh_nbu02 cihcispapp247: standard_unix_corp-cis_shared 190635017908 24806407611 9442867181 7.68 20.19 ghnbu gh_nbu02 wavmd003: standard_unix_corp-cis_shared 2760141244 594115253 299382152 4.65 9.22 ghnbu gh_nbu02