Boga Srinivas <[EMAIL PROTECTED]> wrote: oryann9 wrote: > I am trying to get the equivalent in KSH to work in Perl and I cannot seem to > get the same output. I need from /etc/passwd name, uid, gid and gecos for > each passwd files. > > IN KSH: > > for i in `ls /var/tmp/passwd.*` > do > print $i; > print "\n"; > awk 'FS=":" {print $1,"\t",$3,"\t",$4,"\t",$5}' $i; > print "\n"; > done > > IN PERL > > use strict; > use warnings; > > my @array = glob("/var/tmp/passwd.*"); > my ($file,@name,@uid,@gid,@cmts); > foreach $file (@array) { > { local $/ = undef; > open (FILE, "+<$file") or die $!; > (@name,@uid,@gid,@cmts) = (split /:/, ) [0,2,3,4],"\n"; > print ("@name\n"); > print ("@uid\n"); > print ("@gid\n"); > print ("@cmts\n"); > } > } > > Perl Output: > root 0 3 > root 0 3 NS2 Root > root 0 3 tpgdrpp1 Root > ... > > > Desired and KSH output : > > /var/tmp/passwd.admbakp1.hpux > > root 0 3 > daemon 1 5 > bin 2 2 > sys 3 3 > adm 4 4 > uucp 5 3 > lp 9 7 > nuucp 11 11 > hpdb 27 1 ALLBASE > > Try this,
#!/usr/bin/perl open( PASSWD, "/etc/passwd" ); while( ) { chomp; @arr = split (/:/); @[EMAIL PROTECTED],2,3,4]; print "\n @res"; } -- Boga Srinivas System Engineer cool, thanks! I modified it so it will work on multiple files. use strict; use warnings; my @glob = glob("/cygdrive/c/temp/passwd.*"); my (@arr,@res,$file) = (); foreach $file (@glob) { open (FILE, "+<$file") or die "file: '$file' did not open $!"; { local $/ = undef; my $contents = <FILE>; chomp $contents; @arr = split (/:/, $contents); @[EMAIL PROTECTED],2,3,4]; print "\n @res"; } } print "\n"; close (FILE); derek __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com