Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > addin lines to existing csv file with fastercsv

Reply
Thread Tools

addin lines to existing csv file with fastercsv

 
 
Mark Stroeve
Guest
Posts: n/a
 
      05-18-2007
I'am trying to add new lines to a existing csv file, but i only get one
line.
It doesn't add additional lines, i pasted te code below, has anyone a
suggestion how to write new lines?


require 'fastercsv'


FasterCSV.open("d:/file.csv", "w") do |csv|
csv << [@params[:ha_gewas2], "first name", "last name", "email"]
end

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Stephen Smith
Guest
Posts: n/a
 
      05-18-2007
> It doesn't add additional lines, i pasted te code below, has anyone a
> suggestion how to write new lines?

You need to insert newlines after each record string.

For example:
hdr = [['field1a', 'field1b'], 'field2', 'field3',
'field4'].flatten.join(',')
FasterCSV.open("my_csv_file.csv", "w") {|file|
file << hdr + "\n" # There's a different newline
thingamajigger for Windows: \r\n
# proceed with adding additional records here.
}
>
>
> require 'fastercsv'
>
>
> FasterCSV.open("d:/file.csv", "w") do |csv|
> csv << [@params[:ha_gewas2], "first name", "last name", "email"]
> end
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      05-18-2007
On Fri, May 18, 2007 at 09:06:39AM +0900, Mark Stroeve wrote:
> I'am trying to add new lines to a existing csv file, but i only get one
> line.
> It doesn't add additional lines, i pasted te code below, has anyone a
> suggestion how to write new lines?
>
>
> require 'fastercsv'
>
>
> FasterCSV.open("d:/file.csv", "w") do |csv|
> csv << [@params[:ha_gewas2], "first name", "last name", "email"]
> end


Open using "a" instead of "w" to append to the file. See "ri IO" for a list
of file modes.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using FasterCSV to clean CSV file John Mcleod Ruby 7 11-18-2009 11:49 PM
CSV file to database problem - FasterCSV::MalformedCSVError John Mcleod Ruby 1 07-16-2009 03:37 PM
update a field in CSV file using fastercsv Li Chen Ruby 10 09-24-2008 01:48 PM
Advice on handling malformed CSV with FasterCSV Wes Gamble Ruby 1 12-18-2006 09:43 PM
[ANN] FasterCSV 0.1.3--CSV parsing without the wait! James Edward Gray II Ruby 0 11-16-2005 08:31 PM



Advertisments