Last active
October 3, 2015 17:38
-
-
Save msonnabaum/5c31bec95a4d2c8ddf53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
require "csv" | |
def fix_dstat_csv(file) | |
dstat_csv = CSV.read file | |
# Shift off useless metadata rows | |
dstat_csv.shift 5 | |
# dstat spreads the headers out over two rows, which R does not like, so | |
# combine them into one. | |
headers = dstat_csv[0].each_with_object([]) do |header, res| | |
res << "#{(header || res.last)}" | |
end | |
dstat_csv[1].map! {|header| "#{headers.shift}-#{header}"} | |
dstat_csv.shift | |
CSV do |csv| | |
dstat_csv.each {|row| csv << row} | |
end | |
end | |
fix_dstat_csv ARGV[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment