Using CSV and STDIO?

I would like to create a CSV filter, so I want to read from STDIN and
write
to STDOUT.

This does not work, even though this is per the the CSV web
documentation:

require “rubygems”

require “csv”

require “nokogiri”

CSV($stdin, { :headers => true }){ |csv_in| csv_in.each { |row| p row }
}

/Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1871:in `block
(2
levels) in shift’: Unquoted fields do not allow \r or \n (line 1).
(CSV::MalformedCSVError)

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1836:in
`each’

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1836:in
`block
in shift’

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1796:in
`loop’

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1796:in
`shift’

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1738:in
`each’

from tt.rb:6:in `block in ’

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1048:in
`instance’

from /Users/joe/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:2320:in
`CSV’

from tt.rb:6:in `’

Any thought?

On Jun 5, 2015, at 12:12 PM, [email protected] wrote:

Any thought?

Like the error message says:

Unquoted fields do not allow \r or \n (line 1). (CSV::MalformedCSVError)


Scott R.
[email protected]
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice

On Jun 5, 2015, at 2:50 PM, [email protected] [email protected] wrote:

Well, this is an example straight from the documentation.

I was hoping someone would post an example of using the csv class with stdio…

The error message is claiming that the data you’re sending is
malformed–that’s not (directly) related to whether the data is coming
from a file vs stdio.


Scott R.
[email protected]
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs