Skip to content

Instantly share code, notes, and snippets.

@jdudek
Created January 31, 2011 19:28
Show Gist options
  • Save jdudek/804632 to your computer and use it in GitHub Desktop.
Save jdudek/804632 to your computer and use it in GitHub Desktop.
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
Copy link

ptoche 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