On Tue, Nov 18, 2008 at 10:51:29PM +0900, Bil K. wrote:
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