# Problem with zipfile.read -\> array (line by line)

**URL:** <https://www.ruby-forum.com/t/problem-with-zipfile-read-array-line-by-line/119626>\
**Category:** Ruby\
**Created:** [November 8, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/problem-with-zipfile-read-array-line-by-line/119626 "2007-11-08T17:36:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 8, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/problem-with-zipfile-read-array-line-by-line/119626/1 "2007-11-08T17:36:39Z")

</div>

Hi,

have anybody a hint how i could extract information only for the  
first column in a zipped csv.  
The hole csv-file is in the array instead line by line as i’m  
expected, so i get only the first  
character.

#match\_f.csv are 3-column and many millions row file.  
Zip::ZipFile.open(“f:/base\_data/match\_df.zip”,Zip::ZipFile::CREATE)  
{ |zipfile|  
array=zipfile.read(“match\_df.csv” ).split("\t")  
puts array[0]  
}

many thanks for advance  
Christian

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 8, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/problem-with-zipfile-read-array-line-by-line/119626/2 "2007-11-08T19:05:03Z")

</div>

Hi Christian,

> puts array[0]  
> }

You can also use a csv library (e.g. fasterCSV  
[http://fastercsv.rubyforge.org/](http://fastercsv.rubyforge.org/), or the standard Ruby one).

If you want to process the file line by line, you should split it on  
“\n”, then process each line. Code-snippet:

zipfile.read(“match\_df.csv” ).split.each do |row|  
puts row.split(“,”)[0]  
end

In the second split, you should use the delimiter used in the csv file  
(\t for instance).

Cheers,  
Peter

* * *

[http://www.rubyrailways.com](http://www.rubyrailways.com)  
[http://scrubyt.org](http://scrubyt.org)

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 8, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/problem-with-zipfile-read-array-line-by-line/119626/3 "2007-11-08T21:35:36Z")

</div>

On 8 Nov., 19:04, Peter S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > { |zipfile|  
> > puts row.split(“,”)[0]  
> > end
> 
> In the second split, you should use the delimiter used in the csv file  
> (\t for instance).
> 
> Cheers,  
> Peter  
> \_\_\_[http://www.rubyrailways.comhttp](http://www.rubyrailways.comhttp)://scrubyt.org

great! , many thanks  
Christian
