Created
November 20, 2013 17:06
-
-
Save wazoo/7566898 to your computer and use it in GitHub Desktop.
Quick script to parse out units in VMware vCOPs CSV Reports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# vcops_parse.rb | |
# | |
# By: Ben Thomas, Nov 20 2012 | |
# | |
# MIT License | |
# | |
# Removes units from vCOPs CSV report columns, because then you can sort them correctly. | |
# Turns this: | |
# Disk Space Total Used | |
# 1 GB | |
# 5 GB | |
# | |
# In to this: | |
# Disk Space Total Used (GB) | |
# 1 | |
# 5 | |
# run like this: ./vcops_parse.rb <filename.csv> && open <filename.csv>_fixed.csv | |
require 'csv' | |
csv_in = CSV.read(ARGV[0]) | |
CSV.open("#{ARGV[0]}_fixed.csv", "wb") do |csv| | |
headers = Array.new | |
csv_in[0].each_with_index do |col,i| | |
headers[i] = "#{col} (#{csv_in[1][i].split(' ')[-1]})" | |
end | |
csv << headers | |
csv_in.shift | |
csv_in.each do |row| | |
new_row = Array.new | |
row.each do |col| | |
case col | |
when /vCPUs/, /MHz/, /GHz/, /GB/, /MB/, /KB/ | |
col = col.to_f | |
when '-' | |
col = "0" | |
end | |
new_row << col | |
end | |
csv << new_row | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment