From: david wright Date: 2008-11-19T15:37:25+09:00 Subject: Re: selected field assignment --- On Tue, 11/18/08, Bil Kleb wrote: > From: Bil Kleb > Subject: selected field assignment > To: "ruby-talk ML" > Date: Tuesday, November 18, 2008, 8:51 AM > Hi, > > I'm grabbing the owner and file names from `find . > -perm -g+r -ls` > which has ls -dgils output like, > > 6744065 8 -rw-r--r-- 1 kleb users > 289 Nov 30 > 2007 Ruby/README > > with something like, > > find_result.each_line do |line| > fields = line.split > user_name, file_name = fields[4], fields.last > > I've also played with, > > _,_,_,_,user,_,_,_,_,_,file = a.split > > But both leave me thinking there is a better way without > resorting > to a regex? > > Thanks, > -- > http://twitter.com/bil_kleb looks like you got several possible suggestions. here is one more, not exact but plausible. avoid system calls, do it all in ruby. #!/usr/bin/env ruby require 'find' require 'etc' path = ENV["HOME"]+'/ruby' Find.find(path) do |file| if FileTest.directory?(file) if File.basename(path)[0] == ?. Find.prune else next end else f = File.new(file) s = f.stat g_read = sprintf("%o", s.mode) if ( g_read.to_i >= 100640 ) print "file: #{file}\t" puts "owner: #{Etc.getpwuid(s.uid).name}" end end end