# Addin lines to existing csv file with fastercsv

**URL:** <https://www.ruby-forum.com/t/addin-lines-to-existing-csv-file-with-fastercsv/104445>\
**Category:** Ruby\
**Created:** [May 18, 2007, 2:06am UTC](https://www.ruby-forum.com/t/addin-lines-to-existing-csv-file-with-fastercsv/104445 "2007-05-18T02:06:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [May 18, 2007, 2:06am UTC](https://www.ruby-forum.com/t/addin-lines-to-existing-csv-file-with-fastercsv/104445/1 "2007-05-18T02:06:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [May 18, 2007, 2:22am UTC](https://www.ruby-forum.com/t/addin-lines-to-existing-csv-file-with-fastercsv/104445/2 "2007-05-18T02:22:56Z")

</div>

> 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.  
}

---

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [May 18, 2007, 7:10am UTC](https://www.ruby-forum.com/t/addin-lines-to-existing-csv-file-with-fastercsv/104445/3 "2007-05-18T07:10:17Z")

</div>

On Fri, May 18, 2007 at 09:06:39AM +0900, Mark Stroeve wrote:

> ```
> 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.
