Hi,
And welcome to LQ!
I don't know the complexity of your schema (many multi-value attributes?), and haven't
got a clue what sqlloader is or does, but if the task at hand is simple enough I can
throw you a script I've written here for a similar purpose.
Code:
# Author: tink
# purpose: make a CSV file to feed into Oracle from an LDIF file as
# produced from an ldapsearch
#
BEGIN{
# Set-up an array with the names that ORA requires out of the LDIF
# the o[1-4] fields are dummys which we will export empty
list[1]="cn"
list[2]="givenname"
list[3]="o1"
list[4]="sn"
list[5]="attribute1"
list[6]="mail"
list[7]="o2"
list[8]="attribute2"
list[9]="attribute3"
list[10]="attribute4"
list[11]="attribute5"
list[12]="o3"
list[13]="attribute6"
list[14]="attribute7"
list[15]="o4"
list[16]="role"
list[17]="attribute8"
list[18]="attribute9"
list[19]="attribute10"
# Tell awk to ignore case in pattern matching, just for good measure
IGNORECASE=1
RS="\n\n"
FS="\n"
ORS="\n\n"
OFS="\n"
}
{
if( $0 ~ /objectClass: Person/ ){
# the fields get parsed and assigned to an array with the "Field name"
# as the index (see the field names above). Basically something like
# "sn=Jones" gets assigned to res["sn"]=Jones
for( i = 1; i <= NF; i++ ){
for( l in list ){
if( $i ~ "^"strip( list[l]) ){
res[strip( list[l])]= strip( rparse( $i ))
}
}
}
# print the fields of the array mentioned before in order
for( j=1;j<=18;j++ ){
printf( "\"%s\",", res[list[j]])
}
printf "\"%s\"\n",res[list[19]]
}
}
# get the "name" of a field
function lparse( var ){
return gensub( /([^:]+):.+/, "\\1", "g",var)
}
# get the "value" of a field
function rparse( var ){
return gensub( /[^:]+:(.+)/, "\\1", "g",var)
}
# remove leading and trailing whitespace
function strip( var ){
return gensub( /^ *([^ ]+)/, "\\1", "1", gensub( /([^ ]+) *$/, "\\1", "1", var ) )
}
For reasons of anonymity I renamed attributes that are specific to my field of work
with attributeX, but you may get the idea. Note that in the code the loops match the
number of attributes we defined for the array above.
Cheers,
Tink