Parsing Unix /etc/passwd File
Join the DZone community and get the full member experience.
Join For Free// 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();
Opinions expressed by DZone contributors are their own.
Trending
-
5 Key Concepts for MQTT Broker in Sparkplug Specification
-
Writing a Vector Database in a Week in Rust
-
What Is React? A Complete Guide
-
Building a Flask Web Application With Docker: A Step-by-Step Guide
Comments