From: anne001 Date: 2005-11-21T10:37:22+09:00 Subject: Parsing excel CVS data on a mac OSX to extract blocks of cells I would like to parse some excel CVS data which has a repetitive block pattern "Experiment ID: 1",,,,,,,,,,,, "Subject ID: 1013938829432171e868c340. Trial,stimulus,time,type,field1,field2,text_response,Abs. time of response,,,,, 26,undefined,14828,KEY,RETURN,UNUSED,DCS,Sat Oct 15 17:48:04 GMT-0400 2005,,,,, 23,undefined,15078,KEY,RETURN,UNUSED,244,Sat Oct 15 17:48:19 GMT-0400 2005,,,,, 7,nixontrialleft copy.pct [TAG: 1],5953,KEY,1,UNUSED,,Sat Oct 15 17:49:24 GMT-0400 2005,,,,, 8,nixontrialfront copy.pct [TAG: 3],6250,KEY,3,UNUSED,,Sat Oct 15 17:49:31 GMT-0400 2005,,,,, 9,nixontrialright copy.pct [TAG: 2],2469,KEY,2,UNUSED,,Sat Oct 15 17:49:34 GMT-0400 2005,,,,, ##### more data ###### ,,,,,,,,,,4374.347222,, ,,,,,,,,,,,,1.00 ,,,,,,,,,,,,0.93 ### and a new block starts "Experiment ID: 3",,,,,,,,,,,,0.92 .... Question 1: ------------------ Arr = IO.readlines(File.expand_path("~/Desktop/FaceRetest.cvs")) has a length of 1, why? I noticed that the puts has ^M everywhere Arr = IO.readlines(File.expand_path("~/Desktop/FaceRetest.cvs"),sep_string="^M") seems to split the array into lines. Arr = Arr.split(",") gives me a message, private method `split' called puts Arr.length gets me no response. I expected split to take the 1D array and transform it into a 2D array. What is the best way to get the excel CVS data into a Ruby 2D array for further analysis? Question 2: ----------------- Once I have a 2D array, what is the best way to find the index of the key word Trial (which starts the data I want). In matlab, I would do something like, Find the index pair (I,J) at which Array = Trial If J==1 Extract the array starting at row I+1 to I+82, for columns [2, 3, and 5] and I would love some pointers at Ruby structures, methods, etc I need to look at. - First ruby code -- Thanks for your help