Update: actually the following not going to be quite correct... need to pack the IP addresses as integers for the sort... so a more generalised (schwartzian) transform is probably better. See my next post in this thread.
use warnings;
use strict;
open(file_info,$file) or die "Can't open $file ";
my @records;
while (<file_info>) {
my ( $src_ip, $src_port ) = /IP\s+(\d+(?:\.\d+){3})\.(\d+)/;
my ( $dst_ip, $dst_port ) = />\s+(\d+(?:\.\d+){3})\.(\d+)/;
push @records, [$src_ip , $src_port , $dst_ip , $dst_port];
}
close(file_info);
my %seen;
my @result =
sort {
$a->[0] != $b->[0] ? $a->[0] <=> $b->[0]
: $a->[1] != $b->[1] ? $a->[1] <=> $b->[1]
: $a->[2] != $b->[2] ? $a->[2] <=> $b->[2]
: $a->[3] <=> $b->[3]
}
map { $seen{(join(',',@$_))}++ ? () : $_ } @records;
print join(' ',@$_)."\n" for @result;
-David