0

I just want to read a csv file and discard the header row.

When I do csv = CSV.read('file_name.csv','r') I get

.rvm/rubies/ruby-1.8.7-head/lib/ruby/1.8/csv.rb:98:in `read': can't convert String into Integer (TypeError)

When I do

csv = CSV.open('file_name.csv','r')
csv.shift

I get

.rvm/rubies/ruby-1.8.7-head/lib/ruby/1.8/csv.rb:639:in `get_row': CSV::IllegalFormatError (CSV::IllegalFormatError) from .rvm/rubies/ruby-1.8.7-head/lib/ruby/1.8/csv.rb:567:in `shift'

What is an example of successfully reading csv files and manipulating data in ruby 1.8.7?


edit:

first few lines of file_name.csv

Request, Target
http://www.asdf.com/,http://www.asdf.com/
http://www.asdf.com/_blank,http://www.asdf.com/
"http://www.asdf.com/,",http://www.asdf.com/
ahnbizcad
  • 10,491
  • 9
  • 59
  • 85
  • 1
    Please post the content of file_name.csv, or at least the first lines. – kxmh42 Aug 31 '16 at 20:24
  • 1
    If you're still using Ruby 1.8.7 you're in dire need of updating, but you might be able to muddle along using the [CSV library](http://ruby-doc.org/stdlib-1.8.7/libdoc/csv/rdoc/CSV.html) if you read the documentation carefully. Keep in mind this is **unsupported software** so you're basically on your own. – tadman Aug 31 '16 at 20:33

2 Answers2

1

Do it like this:

csv = CSV.read('file_name.csv')

"r" is not a correct parameter for CSV.read

kxmh42
  • 3,121
  • 1
  • 25
  • 15
0

The file line endings was the issue. I changed all of them to unix's LF.

ahnbizcad
  • 10,491
  • 9
  • 59
  • 85