This is where the magic Associative Arrays (Better Known as Hashes) come
into play.
I'd create process to reach each and every line into a for loop.
Split out your various fields using the split command.
Then do an increment on each element in an associative array within the
loop.
i.e.
$machines{$machine}++;
$ips($ip)++;
You can even bring out the all the elements in the line with a separate
hash.
Then when you've traversed the entire file, you just spit out the values
stored in your hash looking for any value that is greater than 1 and
that will find your duplicates.
Some pseudo code:
Open file
While not end of file.
Split ling into various elements ($ip, $machine, etc).
Increment an associative array value in each element.
Continue while loop.
End while loop
Sort through the has keys looking for only values that are greater than
1. This will present a listing of your duplicates.
Hope this helps...
-d
David K Hill
Sr Systems Engineer
Intel Corporation
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
King, Dan
Sent: Monday, May 08, 2006 11:23 AM
To: [email protected]
Subject: Finding partly duplicated records
I am at my wits end on this question. I feel like the answer is
probably simple but it has me beat.
I have a list of machines and IP addresses. The combination,
$machine and $IPAddress is never duplicated in the list. However,
$IPAddress may be duplicated and $machine may be duplicated.
For example:
m001ws 192.168.20.2
m002ws 192.168.20.4
m003ws 192.168.20.6
m003ws 192.168.20.10
m004ws 192.168.20.9
m005ws 192.168.20.20
m006ws 192.168.20.12
m009ws 192.168.20.12
I want to find m003ws with its two IP addresses
m003ws 192.168.20.6
m003ws 192.168.20.10
and 192.168.20.12 with its two machines.
m006ws 192.168.20.12
m009ws 192.168.20.12
I also have a longer record consisting of about 9 fields where I want
to know if there is a duplication within one of the fields. For example
any time a userid appeared in more than one record.
I was thinking that these are basically the same problem but I can't
seem to find any examples on the web. I would appreciate any help.
By the way, in the real problems I am looking at several thousand
'records' and I need to run these reports once a day.
Dan
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs