Skip to content

Instantly share code, notes, and snippets.

@oisin
Created August 12, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisin/9172bc266f4bd6badee8aed3d95dfb61 to your computer and use it in GitHub Desktop.
Save oisin/9172bc266f4bd6badee8aed3d95dfb61 to your computer and use it in GitHub Desktop.
Some ruby for breaking up AWS bills in XLSX form.
#!/usr/bin/env ruby
require 'creek'
fname = ARGV[0]
abort("Please supply file name") if fname.nil?
book = Creek::Book.new fname, with_headers: true
allocations = book.sheets[0]
rowid = 0
allocations.simple_rows.each { |r|
rowid += 1
desc = r['ItemDescription'] || next
# puts r
if (r['ItemDescription'].include?('reserved instance'))
match = /([a-z][0-9][a-z]*\.\w+) /.match(r['ItemDescription'])
puts("%s,%s" % [r['AvailabilityZone'] || "no az", match[1] || match[0]], r['user:Service'] || "no service", r['user:Role'] || "no role", r['user:Name'] || "no name")
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment