On Wed, Jul 20, 2011 at 7:24 PM, Overkill <[email protected]> wrote:
> Greetings,
>
> I'm trying to increment the UID field of the unix password file from an csv
> file. I've tried to insert C style increment and it keeps bomping out.
> What would be the logic to increment the 5009 to increment by one? Thanks
> for any help.
>
> -Overkill
>
> #!/usr/bin/perl
>
> #use strict;
> #use warnings;
>
> while (<DATA>) {
> chomp;
> ($first, $last, $username) = split(",");
> print "$username:x:5009:4001:$first $last:/home/$username:/bin/**
> false\n";
> }
> exit;
>
> __DATA__
> "Bob","Ahrary","bahrary"
> "Jill","Anderson","janderson"
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
> #!/usr/bin/perl
use strict;
use warnings;
my $userid = 5009;
while (<DATA>) {
chomp;
($first, $last, $username) = split(",");
print "$username:x:$userid:4001:$first $last:/home/$username:/bin/**
false\n";
$userid++;
}
exit;
__DATA__
"Bob","Ahrary","bahrary"
"Jill","Anderson","janderson"
That should do the trick... you could go for a: print "$username:x:" .
$userid++ . ":4001:$first $last:/home/$username:/bin/**false\n"; as well if
you like to keep it shorter. or change $userid++; to $userid +1; or even
$userid = $userid +1; depending on your personal preference. The result is
adding 1 to the $userid variable which is what you are looking to do :-)
Regards,
Rob