Skip to content

Instantly share code, notes, and snippets.

@cgrusden
Last active December 28, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrusden/8c0ba6d3df2795bfefc9a3813123fe1d to your computer and use it in GitHub Desktop.
Save cgrusden/8c0ba6d3df2795bfefc9a3813123fe1d to your computer and use it in GitHub Desktop.
# Run this file after you split the big ass massive .vcard dump from Mac Addressbook / Contacts
# usage: ruby parser.rb > somefile.csv
class VCardParser
def initialize(path_to_file)
@file = path_to_file
end
def method_missing(name, *args, &block)
search_for_line_starting_with(name.upcase).first.to_s.split(":").last.to_s.strip.gsub(/[;,]/, "")
end
def lines
File.new(@file).readlines
end
protected
def search_for_line_starting_with(text)
lines.select { |line| line =~ /^#{text}[\:|\;]/ }
end
end
Dir.glob("*.vcard") do |file|
parser = VCardParser.new(file)
puts [parser.fn, parser.title, parser.org, parser.email].join(",")
end
#!/bin/sh
# Run this first
# Run this against the big ass massive .vcard dump from Mac Addressbook / Contacts
# usage: ./split.vcard.sh <filename>
echo "Starting"
awk '/BEGIN:VCARD/{close("F."i".vcard"); x="F."++i".vcard";}{print > x;}' $1
echo "Done splitting vcf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment