From: Gene Tani Date: 2005-11-21T22:52:25+09:00 Subject: Re: Parsing excel CVS data on a mac OSX to extract blocks of cells anne001 wrote: > Thank you so much for your help > The data was collected by another lab. I don't know what they use. I > saved their excel file data into a csv file. I don't know if there is a > way of telling excel to do a better job. I am on panther, with > office 2004 for mac. > > require "csv" > arr = CSV.read(File.expand_path("~/Desktop/FaceRetest.cvs")) > > I get an error: > /usr/local/lib/ruby/1.8/csv.rb:607:in `get_row': > CSV::IllegalFormatError (CSV::IllegalFormatError) > > Ara's formulation does the same thing. > > I think there is a way to replace special characters in emacs but what > I tried so far does not work. > > I thought I could use readlines and a puts and then copy the ruby > output, which would not longer have the ^M, but somehow, ruby gets > mixed up, and suddenly stop parsing the lines, so I can't relie on ruby > readline either. It sounds like I need to figure out how to format the > input file better. And then I will be able to use your suggestions. > > thank you There's a few ways to handle converting newlines between O/S: - require 'ptools'; File#nl_convert here: http://ruby-miscutils.sourceforge.net/ptools.html - specify $/ input record separator and $\ output separators for IO#gets, readline, each_line etc. - Komodo has a Code / Clean Line Endings which will convert to the O/S format you're running it on but there's no automatic conversion like python open("filename.ext","U"), I think