Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Opera's .adr address book to CSV
# ruby 1.9.2
require "csv"
File.open("contacts2.adr", "r") do |f|
contacts = []
f.read.split("#CONTACT").each do |entry|
unless entry.empty?
contact = {}
entry.each_line do |line|
unless line.empty?
k, v = line.strip.split("=")
contact[k] = v
end
end
contacts << contact
# p contact
end
end
str = CSV.generate do |csv|
csv << %w(name email phone)
contacts.each do |contact|
csv << [contact["NAME"], contact["MAIL"], contact["PHONE"]]
end
end
puts str
end
@ptoche

This comment has been minimized.

Copy link

commented Jun 7, 2016

Just what I needed, thanks for sharing. Note: I replaced puts str with File.write("contacts.csv", str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.