Skip to content

Instantly share code, notes, and snippets.

@deepflame
Created July 15, 2013 04:57
Show Gist options
  • Save deepflame/5997605 to your computer and use it in GitHub Desktop.
Save deepflame/5997605 to your computer and use it in GitHub Desktop.
This Ruby script fills in the blanks in a csv file which has "rowspan".
require 'csv'
FILE_IN = "in.csv"
FILE_OUT = "out.csv"
CSV.open(FILE_OUT, "wb") do |out|
CSV.foreach(FILE_IN) do |row|
@complete_row ||= row
row.each_with_index {|v,i| @complete_row[i] = v if v }
out << @complete_row
end
end
@deepflame
Copy link
Author

Example:

A file that looks like:

Owner,Dog,Food
Tim,Struppi,Bones
,,Meat
Michey,Pluto,Sausage

will be converted to:

Owner,Dog,Food
Tim,Struppi,Bones
Tim,Struppi,Meat
Michey,Pluto,Sausage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment