I have an input array like :
"SVR1" GRP="EVT_BOX06B" SRID=100 MIN=2
"SVR1" GRP="EVT_BOX06B" SRID=200 MIN=1
"SVR2" GRP="ADM_BOX06B" SRID=100 MIN=1
"SVR1" GRP="EVT_BOX88B" SRID=100 MIN=2
"SVR1" GRP="EVT_BOX88B" SRID=200 MIN=1
"SVR2" GRP="ADM_BOX88B" SRID=100 MIN=1
I need to get final output as below :
SVR1 EVT_BOX06B 100 3
SVR2 ADM_BOX06B 100 1
SVR1 EVT_BOX88B 100 3
SVR2 ADM_BOX88B 100 1
The last column in the output is the total count only if the first column & second column are same.
Thanks in advance.
while(<>) {
/"([^"]*)"[^"]*"([^"]*).*?(\d+).*?(\d+)/;
$hash{$1 . '#' . $2}++;
$hash1{$1} = $3;
}
while (($key, $value) = each %hash) {
@tmp = split (/#/, $key);
print "$tmp[0] $tmp[1] $hash1{$tmp[0]} $value\n";
}
As expected.,
$ perl t.pl t1
SVR2 ADM_BOX06B 100 1
SVR1 EVT_BOX88B 200 2
SVR1 EVT_BOX06B 200 2
SVR2 ADM_BOX88B 100 1
Thanks for that piece of code. However, looks like there's some misunderstanding the in the expected output which I have mentioned. The final column is the count of MIN value with same first & second column. For ex.,
"SVR1" GRP="EVT_BOX06B" SRID=100 MIN=2
"SVR1" GRP="EVT_BOX06B" SRID=200 MIN=1
the output should be
SVR1 EVT_BOX06B 3
sed -e 's/[^ ]*=//g' -e 's/"//g'
Thanks summer_cherry, but this code does not add up the last column if values of 1st & 2nd columns are same.