intoperl has asked for the wisdom of the Perl Monks concerning the following question:
$HAN = "handle"; $FILE = "passwd.txt"; open("$HAN", "$FILE")||die "Error opening file: $!\n"; while(<$HAN>) { @arr = <$HAN>; } foreach(@arr) { @IDINFO = split(/:/,"$arr[$_]"); print "UID is: @IDINFO[2] \n"; print "GID is: @IDINFO[3] \n"; }
Passwd File, i am using: xerox:x:10532:151:simmy xrsa:x:222:507:SystemExpert hintest:x:32381:1873:xThin xtactid:x:65446:266:eVenues ricpay:x:30197:1168:Emeral way:x:10010:111:Expressway t061gs:x:80061:3415:Gurav e456988:x:38975:3477:center zrmda01:x:137001:137:Domino lmda02:x:137002:137:Domino TYMFTP:x:51331:2130:Customer ddda03:x:137003:137:Domino ddda04:x:137004:137:Domino dda05:x:137005:137:Domino dda06:x:137006:137:Domino ddm01:x:88085:137:Notes
output: (its only taking first line and printing multiple times) UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507 UID is: 222 GID is: 507
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: traverse through passwd file, and split fields to extract UID/GID
by Corion (Patriarch) on Apr 23, 2014 at 11:21 UTC | |
by intoperl (Acolyte) on Apr 23, 2014 at 13:11 UTC | |
|
Re: traverse through passwd file, and split fields to extract UID/GID
by kcott (Archbishop) on Apr 23, 2014 at 12:06 UTC | |
by intoperl (Acolyte) on Apr 23, 2014 at 13:15 UTC | |
by kcott (Archbishop) on Apr 23, 2014 at 13:46 UTC | |
|
Re: traverse through passwd file, and split fields to extract UID/GID
by choroba (Cardinal) on Apr 23, 2014 at 12:17 UTC | |
by intoperl (Acolyte) on Apr 23, 2014 at 13:17 UTC |