Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to remove duplicate IPs

by rjt (Curate)
on Aug 07, 2013 at 22:53 UTC ( [id://1048454]=note: print w/replies, xml ) Need Help??


in reply to How to remove duplicate IPs

You're close; the next step is to keep track of the IP addresses you have already seen, and print to your output file only if you encounter a new one. I would structure your loop like this:

my %seen; # Remember IPs we have already seen while (<NMAP_DATA>) { next unless /($RE{net}{IPv4})/; print IP_DATA "$1\n" if not $seen{$1}++; }

I used the following test data:

127.0.0.1 host_a whoops, no IP on this line 127.0.1.1 host_b 127.0.0.1 host_a (duplicate!) junk 127.0.0.2 host_c

And got this output:

127.0.0.1 127.0.1.1 127.0.0.2
use strict; use warnings; omitted for brevity.

Replies are listed 'Best First'.
Re^2: How to remove duplicate IPs
by sinhass (Initiate) on Aug 07, 2013 at 23:05 UTC

    Hi RJT, thank you very much for your help. That solves my problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1048454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found