From: Jeremy Hinegardner Date: 2008-11-19T14:58:05+09:00 Subject: Re: selected field assignment On Tue, Nov 18, 2008 at 10:51:29PM +0900, Bil Kleb wrote: > 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? How about this crazy method if you have a find(1) which has -printf. % ruby eval-find.rb Executing command: find . -perm -g+r -type f -printf ' "%p" => "%u",\n' >> file_listing.rb Found 17306 files % find . -perm -g+r -type f | wc -l 17306 % cat eval-find.rb #!/usr/bin/env ruby dir = ARGV.shift || "." file_listing = "file_listing.rb" # opening brace for hash File.open( file_listing, "w+" ) { |f| f.puts "{" } # use find to dump files to an evalable hash format format = " \"%p\" => \"%u\",\\n" cmd = "find #{dir} -perm -g+r -type f -printf '#{format}' >> #{file_listing}" puts "Executing command: #{cmd}" %x[ #{cmd} ] # closing brace for hash File.open( file_listing, "a" ) { |f| f.puts "}" } # now eval the hash listing = eval( IO.read( file_listing) ) puts "Found #{listing.size} files" enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org