Skip to content

Tag Archives: fastercsv

Parsing CSV files with ruby FasterCSV : An example

Need to parse csv files in ruby, skipping the first row (usually some header)?. Use FasterCSV. (Yes, its faster). Install it
$ sudo gem install fastercsv
Here is one solution
#!/usr/bin/ruby -w

require ‘rubygems’
require ‘faster_csv’

#put everything in an array
array_of_arrays = FasterCSV.read(”some_file.csv”)

# remove headers
array_of_arrays.slice!(0)

array_of_arrays.each{|row|
puts row
}
Another solution is

#!/usr/bin/ruby -w

require ‘rubygems’
require ‘faster_csv’

# setting the headers option [...]