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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to remove duplicate IPs
by sinhass (Initiate) on Aug 07, 2013 at 23:05 UTC |