Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'yaml'
- def parse_file(path)
- body = File.read(path)
- .gsub(/^\s*\d+\s*=>\s*/, '').delete('{},').strip
- body.each_line.map {|e| { val: e.to_f, path: path } }
- end
- min_data = Dir['file*'].map {|path| parse_file(path) }
- .transpose
- .map {|e| e.min_by {|v| [v[:val], v[:path]] } }
- # simple
- open('simple.txt', 'w') {|f| min_data.each {|e| f.puts e } }
- # with path
- open('withpath.txt', 'w') do |f|
- min_data.each {|e| f.puts "#{e[:val]}, #{e[:path]}" }
- end
- # yaml
- YAML.dump(min_data, File.open('result.yaml', 'w'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement