By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

process a file in perl

P: 3
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.
Oct 22 '09 #1
Share this Question
Share on Google+
2 Replies


Expert
P: 70
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.
Oct 22 '09 #2

Expert Mod 100+
P: 589
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+)$/
Oct 24 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.