From: Christian Date: 2007-11-09T05:35:02+09:00 Subject: Re: problem with zipfile.read -> array (line by line) On 8 Nov., 19:04, Peter Szinek wrote: > Hi Christian, > > > 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] > > } > > You can also use a csv library (e.g. fasterCSVhttp://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.comhttp://scrubyt.org great! , many thanks Christian