1

I have the following CSV file:

Date,Av,Sec,128,440,1024,Mixed,,rule,sn,version

6/30/2010,3.40,343,352.0,1245.8,3471.1,650.7,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 342,-0.26%,-0.91%,1.51%,-0.97%
6/24/2010,3.40,342,352.9,1257.2,3419.5,657.1,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 341,0.23%,0.50%,-1.34%,0.67%
6/17/2010,3.40,341,352.1,1251.0,3466.1,652.7,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 340,7.77%,5.32%,9.04%,1.71%
6/14/2010,3.40,340,326.7,1187.8,3178.7,641.7,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 339,-0.88%,-0.34%,-0.95%,0.05%
6/11/2010,3.40,339,329.6,1191.9,3209.2,641.4,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 338,0.58%,0.51%,-1.83%,0.99%
6/11/2010,3.40,338,327.7,1185.8,3269.1,635.1,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 335,-0.40%,-0.44%,1.46%,-1.96%
6/11/2010,3.40,335,329.0,1191.0,3221.9,647.8,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 333,-6.83%,-4.70%,-7.04%,-0.32%
6/11/2010,3.40,333,353.1,1249.8,3465.8,649.9,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 332,2.53%,2.02%,1.71%,2.14%

and I want to parse columns 4, 5, 6 and 7 and have four arrays, on which I can do operations like create a line graph against time, etc.

4 Answers 4

4

You need the Ruby CSV module which ships with Ruby. Example:

require 'csv'
require 'pp'

file = File.open( 'bar.csv' )
CSV::Reader.create( file ).each do |row|
  pp row[4..7]
end
Sign up to request clarification or add additional context in comments.

Comments

0

why reinvent the wheel!

Use plugin fastercsv or csv

Comments

0

You are spoiled for choice in parsing CSVs with Ruby, as there are options included in the standard lib, as well as easy home-brewed methods or Open Source libs.

You can start with the examples on "How to parse CSV data with Ruby", and that should point you in the direction for digging deeper.

Comments

0

you can use the smarter_csv Ruby gem and use a :key_mapping to ignore unwanted input columns.

See:

https://github.com/tilo/smarter_csv

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.