On Mon, 2008-10-06 at 07:11 -0700, [EMAIL PROTECTED] wrote:
> Hi,
>
> I have large file in following format:
>
> ID | Time | IP | Code
>
>
> Now I want to write script that will cluster data by IP addr. and
> count total number of IDs for corresponding IP.
>
> I am new to perl.
>
>
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
$Data::Dumper::Maxdepth = 0;
my %data_for = ();
while( <DATA> ){
chomp;
my ( $id, $time, $ip, $code ) = split /\s*\|\s*/, $_;
push @{ $data_for{$ip} }, $_;
}
print Dumper \%data_for;
my %count_for = ();
for my $ip ( keys %data_for ){
$count_for{$ip} = scalar @{ $data_for{$ip} };
}
print Dumper \%count_for;
__DATA__
i001 | 10:56 | 1.2.3.4 | abc
i002 | 11:44 | 2.3.4.5 | abcd
i001 | 12:57 | 1.2.3.5 | xyz
i002 | 04:12 | 2.3.4.5 | xyz
i001 | 17:22 | 2.3.4.5 | xyz
--
Just my 0.00000002 million dollars worth,
Shawn
Linux is obsolete.
-- Andrew Tanenbaum
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/