in reply to Sort passwd by UID
My plan was to sort the file by the UID, and then check for lines with UID = to previous line. Is this the best way?
Not necessarily. The common perl idiom for checking uniqueness is to iterate over all the values, and store the UID in a hash. If it existed before in the hash, it's not uniq. Consider:
my %uids; while (my $line = <$filehandle>) { my $uid = # extract from $line; if ($uids{$uid)) { print "'$uid' is duplicate\n" } else { $uids{$uid} = 1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort passwd by UID
by Saved (Beadle) on Apr 06, 2011 at 13:08 UTC |