|
|
Format LDIF file for Address Book import
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 );
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.07 seconds |
|