Forum: Ruby Modifying cell value in csv without FasterCsv

Posted by sathish k. (sathish_k28)
on 2012-10-12 04:58
Guys,

Below is the content of my csv file

Name   Rank
Antony  10
Mark    12

I have to change the rank value of Antony alone. Headers should not be
affected.I ll be happy of you people come out with solution and snippet.

Note:

without usage of fastercsv. only standard csv should be used.

ruby version: 1.8
Posted by 7stud -- (7stud)
on 2012-10-12 20:11
Read each row of your csv file, and write out each row--incorporating
any changes--to another file.  Delete the original file, then rename the
new file to the old file name.

For most purposes, files can be considered as unchangeable.
Posted by Troy Surrett (Guest)
on 2012-10-12 21:39
(Received via mailing list)
Hi 7stud,

1.8.7 :005 > require 'csv'
 => true
1.8.7 :006 > CSV
 => CSV


http://ruby-doc.org/stdlib-1.8.7/libdoc/csv/rdoc/CSV.html

You might also want to check out the documentation at:

http://ruby-doc.org/core-1.8.7/File.html

Best of Luck,
-Troy
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.