R
rpardee
Hey All,
I've got a file of tab-delimited data that I need to read in. Up until
today this approach has worked wonderfully:
this_file = CSV.open(decrypted_file, "r", "\t")
header = this_file.shift
this_file.each do |line|
# do stuff w/line here
end
this_file.close
But today's file has an entry w/a pair of double-quotes around it. So
now I get:
c:/program files/ruby/lib/ruby/1.8/CSV.rb:639:in `get_row':
CSV::IllegalFormatError (CSV::IllegalFormatError)
from c:/program files/ruby/lib/ruby/1.8/CSV.rb:556:in `each'
I've looked through the rubydocs on CSV & am not finding a method for
telling CSV to expect double-quotes in the file. Is there such a
thing?
Thanks!
-Roy
P.S. I believe the following illustrates the problem--the "F" street
entry line does not seem to parse:
require "CSV" # Lib for working with comma-separated-values
files
somedata = <<END_OF_FILE
userid line1
1-2700 1313 Mockingbird Lane
2-2706 7100 58th Ave SE
4-2718 128 S. "F" Street
3-2712 45 600th Ave. NE
END_OF_FILE
somedata.each_line do |l|
x = CSV.parse_line(l, "\t")[0]
puts x
end
puts "Finished!"
I've got a file of tab-delimited data that I need to read in. Up until
today this approach has worked wonderfully:
this_file = CSV.open(decrypted_file, "r", "\t")
header = this_file.shift
this_file.each do |line|
# do stuff w/line here
end
this_file.close
But today's file has an entry w/a pair of double-quotes around it. So
now I get:
c:/program files/ruby/lib/ruby/1.8/CSV.rb:639:in `get_row':
CSV::IllegalFormatError (CSV::IllegalFormatError)
from c:/program files/ruby/lib/ruby/1.8/CSV.rb:556:in `each'
I've looked through the rubydocs on CSV & am not finding a method for
telling CSV to expect double-quotes in the file. Is there such a
thing?
Thanks!
-Roy
P.S. I believe the following illustrates the problem--the "F" street
entry line does not seem to parse:
require "CSV" # Lib for working with comma-separated-values
files
somedata = <<END_OF_FILE
userid line1
1-2700 1313 Mockingbird Lane
2-2706 7100 58th Ave SE
4-2718 128 S. "F" Street
3-2712 45 600th Ave. NE
END_OF_FILE
somedata.each_line do |l|
x = CSV.parse_line(l, "\t")[0]
puts x
end
puts "Finished!"