Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
1)I like to know how to write perl script that looks through the /etc/passwd file for two or more users with the same first name, and prints those names.

 
Ok - here's a start for you:

my $f = '/etc/password';

open(F,$f) || die "Can't open passwd file\n$!\n";
while(<F>){
[tab]@details_array = split(/:/);
}

will that get you going? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi
Some more detail,
my $f = '/etc/password';

open(F,$f) || die &quot;Can't open passwd file\n$!\n&quot;;
while(<F>){
($uname,$password,$uid,$gid,$username,$home,$shell) = split(/:/,$_);
/* Now you have all fields. But $username you will have full username, may be address and some more comments right, So you do another split */
($firstname,$temp)= split(/\s+/,$username);

//\s+ will splits field by using one or more space

} #end of while


Sachin

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top