From: Jiawei Yong Date: 2011-01-26T11:21:44+09:00 Subject: Re: Obtain data from .csv The thing is i need to extract those data > and transfer those data into an existing yaml file for some reason. DO > you know how to extract for example : > > Maximise use of natural lighting > Turn-off unnecessary lights/equipment > Install energy efficient lighting > Turn-off unnecessary air conditioning > > Thank you > > Kind Regards, > Nizam Hi Nizam, Not too sure about the yaml part (Saw another thread from you on that). I'm not far into Ruby myself, only spending 1 hr max after work reading it since it's not part of my day job, so I'm not answering with FasterCSV or CSV as your file parser, since the concept of extracting data should be the same regardless of parser(I think). I think the data you are asking for is actually indexed 1 after you do the split. In irb, my code below f = File.open("ActionPlan.csv","r") f.each_line{ |line| fields = line.split(',') puts "Field length = #{fields.length}" puts "Fields: 0- #{fields[0]} 1- #{fields[1]}" } gives the following output Field length = 10 Fields: 0- Issue 1- Field length = 10 Fields: 0- 1 1- Efficiency (Energy) Field length = 10 Fields: 0- Action 1- Field length = 10 Fields: 0- 1.a 1- Maximise use of natural lighting Field length = 10 Fields: 0- 1.b 1- Turn-off unnecessary lights/equipment Field length = 10 Fields: 0- 1.c 1- Install energy efficient lighting Field length = 10 Fields: 0- 1.d 1- Turn-off unnecessary air conditioning You should be able to add some logic to filter out the needless fields[1] in the 1st 3 row ("", "Efficiency(Energy)","") if I did not remember wrongly, in the other thread, you were using fields[2]. That will give you "" considering your current csv structure. Regards, yjw -- Posted via http://www.ruby-forum.com/.