Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comma-delim math help 1

Status
Not open for further replies.

moria6

MIS
Jul 11, 2000
30
US
I have a comma-delim file of between 20-30k lines. I'd like to sum the 19th field based on whether the first field is an "I" (Incoming) or an "O" (Outgoing) and sum the number of I's and O's as well. I'd ideally like to see 4 values output: #In, #Out, Size In, Size Out.

For the curious I'm looking at monthly logs of our GroupWise SMTP server and field 19 is the attachment size.

Looking for a push in the right direction rather than a full-fledged solution, please. (Old dog learning new tricks?)

Thanks in advance!

maurie
 
Difficult not to give you the solution, as it's quite a small chunk of code:

my ($i_count,$o_count,$i_size,$o_size) = (0,0,0,0);
while(<FILE>) {
my @fields = split(&quot;,&quot;);
if($fields[0] eq 'I') {
$i_count++;
$i_size += $fields[18];
} else {
$o_count++ if($fields[0] eq 'O');
$o_size += $fields[18];
}

If this isn't quite what you wanted, I'm sure I've given you enough for you to fiddle around with, and get the right solution.

Barbie
Leader of Birmingham Perl Mongers
 
Thanks!

In my &quot;newness&quot; to perl I tried to make it harder than it really was (do I need to learn about regex, should I write the entire file to an array first, etc.)

My perl knowledge just took a &quot;relative&quot; leap thanks to your help.

Also, while I was waiting for the first reply to my question I was looking at other questions, noticed your Perl Mongers site and went to visit. Very nice!

Thanks again for your help!

maurie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top