CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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



FishMonger
Veteran / Moderator

Jul 22, 2009, 12:11 PM


Views: 2078
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

Code
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


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives