Concatenate multiple *.vcf files into one for importing into gMail

Submit to reddit

I have a secondary phone that is running Android. My main phone is still a Nokia N900 for which I gave up trying to sync contacts with gmail. Two options basically exist for n900 none of which works for me:

  1. using MFE which works from time to time
  2. use syncevolution which invariably screws my contacts on the n900 (I guess google’s implementation of syncml or exchange support is dubious at best)

So I devised a third. Since I edit and store all my contacts on the n900 I will export them from time to time (Contacts->Export->All contacts)  and import them manually into gmail. Note that Gmail doesn’t support vCard 3.0; you have to export as 2.1. Unfortunately the n900 will export each contact into a separate file. Since google doesn’t offer bulk import support I thought of concatenating all files into one:

cat *.vcf > all_contacts.vcf

Good idea, but it doesn’t work. In another example of fine programming skills clicking import uploads the file and returns with no contact imported and no error message. Nice one.

It seems some new lines are missing; and so this will work (in the folder with the vcf files)

for i in *.vcf; do cat "$i" >> ../all_contacts.vcf; echo >> ../all_contacts.vcf; done

Import worked now ok!


Here’s courtesy of Adam A Johnson (in the comments below) how to do the same in Windows.

FOR %f IN (*.vcf) DO TYPE "%f" >> all_contacts.vcf & ECHO.  >> all_contacts.vcf


  • Oh man, you saved my life. 394 contacts successfully imported from my N900 to my gmail account, thank you, thank you, thank you!!!

  • Adam A Johnson

     Thanks, this got me on the right track helping my dad import several hundred contacts.  He was stuck on Windows though, so I ended up using:

    FOR %f IN (*.vcf) DO TYPE “%f” >> all_contacts.vcf & ECHO.  >> all_contacts.vcf

    The three parts about the above that were tricky for me were:
    1) Put quotes around the second %f, in case there are any spaces in the .vcf filenames
    2) ECHO.  is the Windows command to echo a blank line – that’s with NO SPACE between the word echo and the period.
    3) Ampersand is the character to chain multiple commands on one line, since Windows FOR loop only executes one line.


    • Thank you for sharing your solution with us! I added it in the article as well, hope that’s ok with you.