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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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

Veteran / Moderator

Jul 22, 2009, 12:11 PM

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

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

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