Over a million developers have joined DZone.

Parsing Unix /etc/passwd File

·
// Here is an easy way to parse the /etc/passwd file.  Perl has built in
functions that only use /etc/passwd as a file.  It's built into the
function and you don't have to declare it.  


#!/usr/bin/perl -w

setpwent();
while (@list = getpwent())  {
     ($LOGIN,$PASSWORD,$UID,$GID,$QUOTA,$COMMENT,$GECOS,$HOMEDIR,$SHELL)
= @list[0,1,2,3,4,5,6,7,8];
    print "$LOGIN,$PASSWORD,$UID,$GID,$QUOTA,$COMMENT,$GECOS,$HOMEDIR,$SHELL\n";
                            }
endpwent();
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}