Splitting up a vcard-file

As my Acer e110 doesn’t sync with Google, all of my precious contacts in the cloud did not automagically appear on my handset. That left me little but no choice to go the old-fashioned way; the export/import-dance.

Exporting from Google is easy, but it generates one vcard-file with all you contacts in it, which the contacts app in Android 1.5 can only import the first entry from. To split up the contacts-file, Scroogle pointed me vCard list-file splitter, vcf-split for short, a Perl script from back in the days when Windows linebreaks apparently were sufficient evidence of the end of a vcard. But times and technology have changed and linebreaks have lost their former glory, meaning I had to slightly alter the script to watch out for a cryptic “END:VCARD” line to indicate the end of a vcard.

And the script goes a little something like this:

# vcf-split - split a .list.vcf file into many small .vcf files.
# Copyright (C) 2004  Raphael J. Schmid.
# Tweaked by Frank Goossens ("futtta") in 2011
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# – raphael.schmid@gmx.de
# – futtta@gmail.com

use File::Basename;

if ($ARGV[0] eq "") {
  print "Usage: vcard-split \n\n";


print $input;

open INPUT, $input or die $!;

while () {
  open OUTPUT, ">> ".$counter."-".basename($input) or die $!;

  if ($_ =~ /END:VCARD/ ) {
    print OUTPUT $_;
    close OUTPUT;
  } else {
    print OUTPUT $_;

close OUTPUT;
close INPUT;

Who knows one day Google will send someone this way who has some vcf-splitting to do?

7 thoughts on “Splitting up a vcard-file

  1. Daniel

    Thanks, that was very useful for splitting my vcard-file. (It came from my Sony cell phone.) Plus, I doubt there is some malicious stuff hidden in those few lines. ;) Much better than all those .exe!

  2. keith

    Sure enough, someone did come from google to find out how to do the vcf split… But, afterwards, what do you do with all the individual little counter files ? I’m looking at splitting it up further and saving them in the database and creating the little jpeg file for the attached pictures …

    1. frank Post author

      well, I just imported the split-up files into my acer contact app, but I guess importing them into a db should not prove to difficult either (if you’re into Perl, that is)? good luck!

      1. keith

        Yep, importing the standard lines into the database should be pretty easy. I’m dealing with a skype vcf file, and there’s one field for photo, I’m trying to figure out how to save that. Nothing I tried worked yet…
        Starts off like this:
        (many lines of binary data with )

        Might as well forget it, too much work!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.