FasterCSV question

R

Reid Thompson

Given a pipe '|' delimited file ala:
rthompso@jhereg:~$ cat pipedata
A|This is text|Is this supposed to error|
A|This is text|Is this supposed to error|
A|This is text|Is this supposed to error|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|

and scripting ala:

rthompso@jhereg:~$ cat pipedata.rb
require 'rubygems'
require 'faster_csv'

FasterCSV.foreach("/home/rthompso/pipedata", :col_sep => '|') do |row|
# use row here...
next if row.empty?
puts row
end

Why are rows that contain quoted data deemed MalFormed?
 
J

James Edward Gray II

A|This is text|Is this supposed to "error"|

This line is not a legal CSV format. To be correct it would need to be:

A|This is text|"Is this supposed to ""error"""|

Luckily, it's a trivial format you shouldn't need FasterCSV to
parse. You can break it down with:

fields = line.split("|")

Hope that helps.

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top