On Thu, Mar 18, 2004 at 07:54:33PM +0900, Allan Wermuth wrote:
> I have tried to rewrite an old short Perl script, that reads a Unix
> password file, and prints loginname and realname if the userid number
> is greater than 100. The Perl script is here:
> 
> #!/usr/bin/perl
> 
> open (PASSWD,"/etc/passwd") || die ("Can't open passwd file!");
> @passwd = <PASSWD>;
> close (PASSWD);
> 
> foreach (@passwd) {
>         @userdata = split(/:/,$_);
>         if (@userdata[0] =~ /^#/) {
>                 next;
>         }
>                 
>         if (@userdata[2] > 100) {
>                 printf "%12s %30s\n", @userdata[0], @userdata[4];
>         }
> }
> 
> # Script ends

File.foreach("/etc/passwd") do |line|
  next if line =~ /^\s*#/
  userdata = line.chomp.split(/:/)
  puts("%12s %30s" % [userdata[0], userdata[4]]) if userdata[2].to_i > 100
end



Regards,

  Michael