I currently have a single column CSV file such as: ["firstname lastname", "firstname lastname", ...].
I would like to create a CSV file such as ["f.lastname", "f.lastname"...]; f being the first letter of the firstname.
Any idea how I should do that ?
update
Ok well, I feel that I am close thanks to you guys, here's what I got so far :
require 'csv'
filename = CSV.read("mails.csv")
mails = []
CSV.foreach(filename) do |col|
mails << filename.map { |n| n.sub(/\A(\w)\w* (\w+)\z/, '\1. \2') }
end
puts mails.to_s
But I still get an error.
update2
Ok this works just fine :
require 'csv'
mails = []
CSV.foreach('mails.csv', :headers => false) do |row|
mails << row.map(&:split).map{|f,l| "#{f[0]}.#{l}@mail.com" }
end
File.open("mails_final.csv", 'w') {|f| f.puts mails }
puts mails.to_s
Thanks a lot to all of you ;)