Skip to content

Instantly share code, notes, and snippets.

@ptoche
Forked from jdudek/convert.rb
Last active June 7, 2016 07:09
Show Gist options
  • Save ptoche/5cd03e12c69c54e2f35f92aa2fcf8315 to your computer and use it in GitHub Desktop.
Save ptoche/5cd03e12c69c54e2f35f92aa2fcf8315 to your computer and use it in GitHub Desktop.
Convert Opera's .adr address book to CSV
#!/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
@ptoche
Copy link
Author

ptoche commented Jun 7, 2016

how to run ruby program named prog.rb

  1. Go to the directory

    $ cd Ruby
    $ ls -la

-rw-r--r--@ ETC.

  1. add the following header to the top of the ruby script

    !/usr/bin/env ruby

  2. make file executable by running

    $ chmod +x prog.rb
    $ ls -la

-rwxr-xr-x@ ETC.

  1. At terminal prompt, run

    $ ./prog.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment