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

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

Hi Christian,

puts array[0]
}

You can also use a csv library (e.g. fasterCSV
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://scrubyt.org

On 8 Nov., 19:04, Peter S. [email protected] 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://scrubyt.org

great! , many thanks
Christian