Max, first of all, this is not a csv file.. but if you are willing to 
make it a real csv file then you can do something like the following:

#!/usr/bin/env ruby

schools = []
ARGV.each do |f_name|
  File.open(f_name) do |f|
    headers = f.gets.chomp.split(/\s*,\s+/)
    while(line = f.gets) do
      schools << [headers, 
line.chomp.split(/\s*,\s*/)].transpose.inject({}) do |h, pair|
        h[pair.first] = pair.last
        h
      end
    end
  end
end
p schools


which gives:

./combine file_a.csv file_b.csv
[{"Name"=>"Fake Hill", "Size"=>"450", "Type"=>"Secondary"}, 
{"Name"=>"Brook Street", "Size"=>"300", "Type"=>"Primary"}, 
{"Name"=>"Notting Hill", "Size"=>"450"}, {"Name"=>"Camden Street", 
"Size"=>"200"}]

hth

ilan

Max Williams wrote:

> 
> file_a.csv
> Name          Type         Size
> Fake Hill     Secondary    450
> Brook Street  Primary      300
> 
> file_b
> Size  Name
> 450   Notting Hill
> 200   Camden Street
> 

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to