 |
|
Home:
Perl Programming Help:
Intermediate:
Re: [ozdersin] awk , uniq , sort , grep:
Edit Log
|
|

FishMonger
Veteran
Jul 22, 2009, 12:11 PM
Views: 1457
|
|
Re: [ozdersin] awk , uniq , sort , grep
|
|
|
There are several of my clarification questions that are still unanswered, so I'll make assumptions on those items. Since $application is null in most cases, I'll leave that out for now. You didn't say if you need a count on the duplicate entries, so I'll leave it out. You didn't say how much memory you have, but I'll assume you can load the whole file into memory. This comes down to a very slightly modified version of my first post
open my $fh, '<', $data_file or die "failed to open '$data_file' $!"; while( <$fh> ) { my ($mac, $ip) = (split(/ /, $_))[3,5]; $uniq{ $mac } = $ip; } close $fh; foreach my $mac ( sort keys %uniq ) { # sorts by mac addresses lexically # if you need to sort numerically, do this instead # foreach my $mac ( sort {$a <=> $b} keys %uniq ) print "$mac \t $uniq{$mac}\n"; }
(This post was edited by FishMonger on Jul 22, 2009, 12:13 PM)
|
|
|
Edit Log:
|
|
Post edited by FishMonger
(Veteran) on Jul 22, 2009, 12:13 PM
|
|
|  |