ruby on rails - How parse the data from TXT file with tab separator? -


i using ruby 1.8.7 , rails 2.3.8. want parse data txt dump file separated tab.

in txt dump contain css property has invalid data.

enter image description here

when run code using fastercsv gem

  fastercsv.foreach(txt_file, :quote_char => '"',:col_sep =>'\t', :row_sep =>:auto, :headers => :first_row) |row|   col= row.to_s.split(/\t/)   puts col[15]   end 

the error written in console "illegal quoting on line 38." can 1 suggest me how skip row has invalid data , proceed data load process of remaining rows?

here's 1 way it. go lower level, using shift parse each row , silent malformedcsverror exception, continuing next iteration. problem loop doesn't nice. if can improve this, you're welcome edit code.

fastercsv.open(filename, :quote_char => '"', :col_sep => "\t", :headers => true) |csv|   row = true   while row     begin       row = csv.shift       break unless row        # things row here...     rescue fastercsv::malformedcsverror       next     end   end end 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -