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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
WRite a Perl script named usernames.pl that looks through the /etc/passwd file for two (or more) users with the same first name, and prints those names.

Hint: after extracting the first name, create a hash with the name for a key and the number of times it was seen as the value. When teh last line of teh fale has been read, look through the hash for counts of greater than one.

This is what i have so far!

while (<WHO>) {
($login, $rest) = /^(\s+(.*)/;
$login = $real {$login} if $real{$login};
printf &quot;%-30s %s\n&quot; , $login, $rest;
}

 
maybe i'm confused but what exactly is the question? Mike
~~~~
simanek@uiuc.edu
&quot;It's a Swingline!&quot;
~~~~
 
try this script:

while (<>) {
@a=split /:/;
@b=split &quot; &quot;,$a[4];
$x{$b[0]}++;
push @{$z{$b[0]}},$a[4]
}
for (keys %x) {
$x{$_}>1 or next;
print join(&quot;\n&quot;,@{$z{$_}}),&quot;\n&quot;;
}

if this is on file &quot;run.pl&quot;, then run as :
perl run.pl < /etc/passwd

--
pkiller

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top