Ok, I think we can solve both of those problems with the same thing. Try something like this:
#!/usr/bin/perl
$nf="endo";
foreach $file (@ARGV) {
open (PASSWD, "$file") || die "Couldn't open $file\n";
while (<PASSWD>) {
($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/);
$USERS{${file}.${login}} = $gcos;
#this way the first key is "passwd.server1.root"
}
close (PASSWD);
}
open (NEWFILE, ">$nf");
foreach $login (sort keys %USERS) {
print NEWFILE "$login, $USERS{$login}\n";
}
close (NEWFILE); # just because I'm tidy
and now you call your script with script.pl passwd*
|