Aqui está um script Perl para fazer isso.
while (<>) {
chomp;
my ($name, $pass, $gid, $users) = split ':';
my %userset;
my @users = split ',', $users;
# create a set (a hash with undef keys) by assigning to hash slice
@userset{@users} = ();
$users = join ',', sort(keys(%userset));
print join(':', $name, $pass, $gid, $users). "\n";
}
Use assim:
$ ./fixgroups <group >group.tmp
$ diff -u group group.tmp
-somegroup::100000:userA,userB,userC,foo,bar,snafu,userB,userB
+somegroup::100000:bar,foo,snafu,userA,userB,userC
$ mv group.tmp group