Keenan, Greg John (Greg)** CTR ** wrote:
Hi,
I have to combine several Unix password files and remove any duplicate
accounts - putting this into LDAP.
I have the following code that will remove any duplicate whole lines but
I need to remove lines only if the first field of the password file is a
duplicate.
---------------------
use strict;
use warnings;
my $passwdfile = "pwcomb";
my %seen = ();
{
local @ARGV = ($passwdfile);
local $^I = '.bac';
while(<>){
$seen{$_}++;
next if $seen{$_} > 1;
print;
}
}
print "finished";
---------------------
Could someone help with a solution to this?
Hi Greg
This will take all the characters from the beginning of each line up to the
first colon and put it into $field1. The line will be printed only if the value
for $field1 hasn't been seen before.
HTH,
Rob
use strict;
use warnings;
my $passwdfile = "pwcomb";
my %seen;
local @ARGV = ($passwdfile);
local $^I = '.bac';
while (<>) {
my ($field1) = /([^:]+)/;
print unless $seen{$field1};
}
print "finished\n";
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/