Lazy – CSV to LDIF
Posted by M@ on 2010/02/24
#!/bin/bash
# AUTHOR: M@sprackle.org
# PURPOSE: To convert a CSV to LDIF
# LIMITATIONS: Expects the following format use in the CSV.
# Surname,GivenName,UID,Mail,Phone,Description
# It's not pretty and I could move it to a for loop but this
# really worked on populating a LDAP phone directory.
# You can really tell how lazy I was on this one....
# INSTALL: change script to +x and run with a file option
# USE: modify the FILENAME on the cat and run.
# $ diffy
cat FILENAME.csv | awk -F, '{print "dn: uid="$3",ou=addressbook,dc=example,dc=com""\n""objectClass: top""\n""objectClass: organizationalPerson""\n""objectClass: inetorgperson""\n""objectClass: person""\n""uid: "$3"\n""cn: "$2,$1"\n""mail: "$4"\n""givenName: "$2"\n""sn: "$1"\n""telephoneNumber: "$5"\n""description: "$6"\n"}
0 Comments.