Connecting Tech Pros Worldwide Forums | Help | Site Map

process a file in perl

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: Oct 22 '09
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 3
SVR2 ADM_BOX06B 1
SVR1 EVT_BOX88B 3
SVR2 ADM_BOX88B 1

The last column in the output is the total count (MIN value) only if the first column & second column are same.

Thanks in advance.

Newbie
 
Join Date: Sep 2009
Posts: 15
#2: Oct 22 '09

re: process a file in perl


Since you have not posted any code, I will assume you are just looking for an approach.

Loop through your input array.
For each element of the array, extract the 3 pieces of information you need
by splitting on whitespace, then using the substitution operator to
remove quotes, etc.
Construct a hash key as the concatenation of the 1st 2 columns.
Increment that hash key with the MIN value.
Finally, loop through the hash keys and print the totals.
Member
 
Join Date: Jun 2009
Posts: 55
#3: Oct 24 '09

re: process a file in perl


Or, instead of using 2 steps (split and a substitute regex) to get the needed data, use a single regex that captures the fields.

Expand|Select|Wrap|Line Numbers
  1. /^"(\w+)" GRP="(\w+)" .*=(\d+)$/
Reply