Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Format LDIF file for Address Book import Apps
I couldn't locate any information on Apple or elsewhere on what the proper format for the LDIF file Address Book was expecting, so I thought I would post what worked for me:
  dn: cn=David Martin,mail=davidfmartin@yahoo.com
  objectClass: top
  objectClass: person
  objectClass: organizationalPerson
  objectClass: inetOrgPerson
  givenName: David
  sn: Martin
  cn: David Martin
  mail: davidfmartin@yahoo.com
  TelephoneNumber: 303-555-1212
  FacsimileTelephoneNumber: 303-555-1313
  Pager: 303-555-1414
  Mobile: 303-555-1515
  homePostalAddress: 17/275-09
  ou: 3100
  O: You company name here
  description: Mailstop - 12275, any addl. comments.
Once I knew the format, it was then a simple task to create a template I could use in a Perl program that would convert a proprietary contact database to LDIF, and then import that into Address Book.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,404 views]  

Format LDIF file for Address Book import | 5 comments | Create New Account
Click here to return to the 'Format LDIF file for Address Book import' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Format LDIF file for Address Book import
Authored by: triplef on Apr 18, '03 11:46:36AM

Would be nice if you could post the perl template as well!

Thanks,
TripleF



[ Reply to This | # ]
Format LDIF file for Address Book import
Authored by: davidfmartin on Apr 18, '03 05:42:52PM
I can't post the actual code because of legal reasons but here is a simple sample.

Here is the actual data file. If you cut and paste this there are 3 lines of comments followed by 2 lines of data. The file should be saved as "addresses.txt".

# file format is as follows
# emailx|firstx|lastx|office_phone|fax|pager|cell_phone|office_location|center|d
escription
#
davidfmartin@yahoo.com|David|Martin|303-555-1212|303-555-1313|303-555-1414|303-5
55-1515|17/275-09|3100|Mailstop - 12275
lainie_meilinger@noreply.com|Lainie|Meilinger|303-555-9000|303-555-9001|303-555-
9002|303-555-9003|17/275-10|8100|Mailstop - 12275, My lovely wife.

This is the template file and should be saved as "addresses.tmpl".

dn: cn={$firstx} {$lastx},mail={$emailx}
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
givenName: {$firstx}
sn: {$lastx}
cn: {$firstx} {$lastx}
mail: {$emailx}
TelephoneNumber: {$office_phone}
FacsimileTelephoneNumber: {$fax}
Pager: {$pager}
Mobile: {$cell_phone}
homePostalAddress: {$office_location}
ou: {$center}
O: Perl Programmers Inc.
description: {$description}

This is the perl program and should be saved as AddressBook.pl. You will have to change the perl path at the top to match your perl path

!/sw/bin/perl
# 
# Author: David Martin (davidfmartin@yahoo.com)
# Created: 04/18/2003
# Purpose: Example Program for creating an LDIF file from a simple pipe 
# delimeted flat file for import into OSX Address Book
# 
# Modifications
# -------------

# you must install this from CPAN to parse the template.
use Text::Template;  

# data files 
$IN	= 'addresses.txt';
$OUT 	= 'addresses.ldif';
$TMPL	= 'addresses.tmpl';

# load template parsing module
$tmplConfig = new Text::Template(
        TYPE   => FILE,
        SOURCE => "$TMPL"
);


open( $OUT, ">$OUT") or die( "$0: Unable to open output file: $OUT\n" );
open( $IN, "$IN" ) or die( "$0: Unable to open input file: $IN\n" );

while(  ) {
    	next if /^#/; 	# skip if line stars with comment
	chomp; 		# strip trailing newline
	
	( $emailx, $firstx, $lastx, $office_phone, $fax, 
	  $pager, $cell_phone, $office_location, $center, 
	  $description ) = split(/\|/, $_);				# split on | 
  
	print $OUT $tmplConfig->fill_in();				# write filled in template to output file
}    

close( $IN );
close( $OUT );



[ Reply to This | # ]
Or you could use the DBF2LDIF utility...
Authored by: broadsend on Apr 18, '03 06:21:33PM
A nice little utility called DBF2LDIF can convert DBF and Outlook Express (and other) files to LDIF. You can find it here...

[ Reply to This | # ]
Or you could use the DBF2LDIF utility...
Authored by: davidfmartin on Apr 18, '03 07:16:27PM

Yes this looks cool!

In my case I had to extract data from a custom system i.e., no
tab delimited export format etc. Writing a custom program was
my only option. I am sure many folks like myself have been
tasked with migrating data from an antiquated system to
somthing more modern.



[ Reply to This | # ]
Format LDIF file for Address Book import
Authored by: redmonk on May 19, '03 11:50:46AM

Have you found an LDIF field for group? I'd like to be able to create an LDIF file where all the addresses end up in a group, so I don't have to search through the AB to find the recently imported contacts.



[ Reply to This | # ]