Hope this was useful?#!/usr/bin/perl $file = 'msgcount.txt'; open (LOG, $file); my %records; # creat a hash while (<LOG>) { # each line is parsed by this regular expression: if (/^\S+ (\S+) (\d+)/) { # and the value for the name, which is now in $1 # is increased by the number in $2 $records{$1} += $2; } } # then we go through all keys (the names) # in our %record hash for (keys %records) { # and print out their sum: print "$_: $records{$_}\n"; }
In reply to Re: Parsing a text file
by elmex
in thread Parsing a text file
by nimajneb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |