in reply to How to parse a file with emails and IP's and output a sorted list with a total count
#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1168769 use strict; use warnings; my %ips; while(<DATA>) { /.* (\S+):(\S+)$/ or next; $ips{$1}{$2}++; } for my $who ( sort keys %ips ) { print $who; my @ips; for my $ip ( @ips = sort keys %{ $ips{$who} } ) { print "=> $ip ($ips{$who}{$ip})"; } print $who =~ s/\@.*//r, " total: ", scalar @ips, " unique ip's\n"; } __DATA__ Jul 28 13:42:27 mail vpopmail[47985]: vchkpw-smtp: (PLAIN) login succe +ss joe@example.com:192.168.250.251 Jul 28 13:42:28 mail vpopmail[47992]: vchkpw-smtp: (PLAIN) login succe +ss joe@example.com:192.168.5.23 Jul 28 13:42:29 mail vpopmail[47994]: vchkpw-smtp: (PLAIN) login succe +ss sally@example.com:192.168.10.28 Jul 28 13:42:27 mail vpopmail[47985]: vchkpw-smtp: (PLAIN) login succe +ss fred@example.com:192.168.8.8 Jul 28 13:42:28 mail vpopmail[47992]: vchkpw-smtp: (PLAIN) login succe +ss joe@example.com:192.168.5.23 Jul 28 13:42:29 mail vpopmail[47994]: vchkpw-smtp: (PLAIN) login succe +ss harry@example.com:192.168.10.5
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to parse a file with emails and IP's and output a sorted list with a total count
by mitzyc (Initiate) on Jul 28, 2016 at 23:28 UTC | |
by Anonymous Monk on Jul 28, 2016 at 23:33 UTC |