Skip to content

Instantly share code, notes, and snippets.

@saterus
Created November 8, 2012 05:14
Show Gist options
  • Save saterus/4036949 to your computer and use it in GitHub Desktop.
Save saterus/4036949 to your computer and use it in GitHub Desktop.
Sums Files
dir = ARGV.shift.strip
sum = 0
Dir.glob(dir + "/*.txt").each do |file|
vals = IO.read(file).scan(/\(([0-9]+)\//).flatten.map(&:to_i)
puts "Values extracted: ", vals
s = vals.inject(:+)
puts "File Sum: #{s}"
sum += s
puts "Total Sum: #{sum}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment