ruby on rails - How to find a specific row in csv -


i'm using ruby 1.9.2. csv file follows..,

name,    id,   no,  dept tom,     1,    12,   cs hendry,  2,    35,   ec bahamas, 3,    21,   frank,   4,    61,   ee 

i want print specific row ('tom'). tried out in many ways, didn't find exact result. recommended options "fastercsv". applicable version. also, noticed csv print field column wise. how print entire row using csv in rails. ruby code follows

require 'csv'  csv_text = file.read('sampler.csv') csv = csv.parse(csv_text, :headers => true) csv.each |row|  puts "#{row[:name]},#{row[:id]},#{row[:no]},#{row[:dept]}" end 

puts csv.find {|row| row['name'] == 'tom'} 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -