-
-
Save ptoche/5cd03e12c69c54e2f35f92aa2fcf8315 to your computer and use it in GitHub Desktop.
Convert Opera's .adr address book to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "csv" | |
File.open("contacts.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) | |
contacts.each do |contact| | |
csv << [contact["NAME"], contact["MAIL"]] | |
end | |
end | |
File.write("contacts.csv", str) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to run ruby program named prog.rb
Go to the directory
$ cd Ruby
$ ls -la
-rw-r--r--@ ETC.
add the following header to the top of the ruby script
!/usr/bin/env ruby
make file executable by running
$ chmod +x prog.rb
$ ls -la
-rwxr-xr-x@ ETC.
At terminal prompt, run
$ ./prog.rb