Last active
December 28, 2018 22:22
-
-
Save cgrusden/8c0ba6d3df2795bfefc9a3813123fe1d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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 |
This file contains hidden or 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
#!/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