I exported my contacts from my old phone via the excellent BitPim utility, which produced DOS-format files containing all the contacts. I did it in CSV format and VCF, to cover my bases.

Verizon's contact importer, a great idea in principle, wasn't able to deal with the CSV file, complaining about the column names, and I wasn't able to figure out what format it was expecting.

But it imported the VCF file as one contact with zillions of alternate numbers. Yeesh.

I added an entry by hand on the phone and discovered that it was saving one vcf file per entry, with the name of the file the name of the entry.

So I needed to split the multi-name vcf file:

split -p "BEGIN:VCARD" ../bitpim.vcf

which produces files like xaa, xab, ... and so on.

This uses BSD split from Mac OSX; GNU split doesn't appear to have the -p option.

Now I needed to rename them according to the name in the file, which is stored in the "FN" field. The ${n:0:$x} part was to strip the DOS newline; otherwise the target filename will have the newline in it.

for f in * ; do 
  n=$(grep "^FN" $f | cut -f 2- -d:)
  x=${#n}; x=$((x-1))
  mv $f "${n:0:$x}".vcf
done
changed July 22, 2011