Ruby CSV merge rows

Hi! Every one! I just want to ask if any one knows how to merge rows in
Ruby CSV in this way:
Input
A B C D E F <=headers
X Y 1 1 0 0
X Y 0 0 2 2

Output

A B C D E F <=headers
X Y 1 1 2 2

where 0 is empty cell.

Thank you very much for your help!!!

Use CSV#read.

Class: CSV (Ruby 1.9.2)

It will return either an array of array, or a CSV::Table object if you
added either :headers=>:first_row or :header=>true to the options hash.

Then use CSV::Table::by_col!

Then you can use [] and []= to access and write each column, iterate via
#each. This should get you started

csv is of class CSV::Table

csv.each do |col|
# adapt to your needs
csv[col.first] = col.last.delete_if { |y| y == ‘delete_me’ }
end

Class: CSV::Table (Ruby 1.9.2)

How to merge 2 csv’s into single(seperate) csv wrt ItemId(forein key)

‘text1.csv’ :

ItemId,MFD,AmmountInINR
FA1986,2015-03-07,742.0999999999999
FA1987,2015-03-07,6307.849999999999
FA1988,2015-03-08,445.26
FA1989,2015-03-08,890.52
FA1990,2015-03-09,7346.789999999999

‘text2.csv’:

ItemId,name,place
FA1986,sourabh,bengaluru
FA1987,swapneel,mumbai
FA1988,sunil,chennai
FA1989,suresh,delhi
FA1990,ramesh,kolkatta

merging should give me output in ‘output.csv’ :

ItemId,MFD,AmmountInINR,name,place
details of these fields