How can i read a specific cell value from CSV file on ruby and output the result?

Viewed 36
# CSV EXAMPLE

Price,Title,Description,Image,link
8500,Kamer Sigurie HAC-HFW1220RP-VF 1080P,"Max 30fps@1080P 
2.7-13.5mm vari-focal lens, Angle of View H: 104°~28°
Max. IR length 30m, Smart IR 
IP67, DC12V,2020/04/28/2_1588084898.jpeg,kamer-sigurie-hac-hfw1220rp-vf-1080p"
9900,Kamera Sigurie DH-HAC-HFW2231BP 2MP,"2MP Starlight HDCVI IR Bullet Camera"

I want to get only the title the value "Kamer Sigurie HAC-HFW1220RP-VF 1080P"

Far now i have tried this :

require 'csv' 
filename = "file.csv"

puts CSV.readlines(filename)[1..1] #This puts a single line 
1 Answers

The quotes in your example are misbehaving . There are no closing quotes, and DC12V" messes things up. After this correction:

Price,Title,Description,Image,link
8500,Kamer Sigurie HAC-HFW1220RP-VF 1080P,"Max 30fps@1080P 
2.7-13.5mm vari-focal lens, Angle of View H: 104°~28°
Max. IR length 30m, Smart IR 
IP67, DC12V,2020/04/28/2_1588084898.jpeg,kamer-sigurie-hac-hfw1220rp-vf-1080p"
9900,Kamera Sigurie DH-HAC-HFW2231BP 2MP,"2MP Starlight HDCVI IR Bullet Camera"

you can get the value like this:

require 'csv' 
filename = "file.csv"

puts CSV.readlines(filename,headers: true)[0]["Title"]
Related