0

I've read through the docs but still can't see how to target individual cells and pre- or append strings to cell content. File is fairly large, if that matters (90MBs).

CSV:

2.22,3.33,4.44,5.55
6.66,7.77,8.88,9.99

I need this output:

%text2.22%,%text3.33%,%text4.44%,%text5.55%
%text6.66%,%text7.77%,%text8.88%,%text9.99%
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
chuckfinley
  • 763
  • 11
  • 26

1 Answers1

0

Do you necessarily have to use fastercsv? If your input is really as simple as you show, the following should suffice:

pre_text = '%text'
post_text = '%'
File.open('outfile.csv', 'w') {|of|
    File.readlines('input_file.csv').each {|line|
        of.puts line.strip.split(',').map{|x| pre_text + x + post_text}.join(',')
    }
}
bta
  • 43,959
  • 6
  • 69
  • 99