Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script help preparing an ldif file

Status
Not open for further replies.

rhoover

Programmer
Jun 13, 2003
6
US
I have an ldif file that I am cleaning up in order to import in into Oracle OID which is Oracles LDAP. It has to be in a specific format in order to load. Another problem I am getting stuck at is there is an LDAP attribute the I need to add to each of the 100,000 employees. I need to add cn which should contain the same as uid

current example:
dn: cn=0123456,cn=users,dc=company,dc=com
telephonenumber: 123-246-7890
mail: employee@company.com
uid: 0123456
givenname: New
sn: Employee
orclisVisible: True
objectclass: person
objectclass: organizationalperson
objectclass: inetorgperson
objectclass: orcluserv2

goal:
dn: cn=0123456,cn=users,dc=company,dc=com
telephonenumber: 123-246-7890
mail: employee@company.com
uid: 0123456
cn: 0123456
givenname: New
sn: Employee
orclisVisible: True
objectclass: person
objectclass: organizationalperson
objectclass: inetorgperson
objectclass: orcluserv2

I know that if I go into vi and put the cursor on uid then hit yy then P the line will be duplicated below the current line. But then I would need to change the second occurence of the label in a group of uid to cn. Any help would be greatly appreciated.
 
A question:

does your input file look like your "current example" above?
If not, what does your input file look like?

Add a little color to your PUTTY terminal: faq52-6627
 
Assuming that your input file is exactly as shown in "current example", this should get you the desired output:

Code:
while read LINE
do
  if [[ $(echo $LINE|awk '{print $1}') != "uid:" ]]
  then
    echo $LINE >> out.txt
  else
    echo $LINE >> out.txt
    echo $LINE | awk '{print "cn: "$2}' >> out.txt
  fi
done < in.txt

be sure to change in.txt and out.txt to more appropriate file names.

Add a little color to your PUTTY terminal: faq52-6627
 
I guess you still want only one mail: line as in
thread822-1380085
So, you may try this:
awk '
$1=="mail:" && $1==p{next}
{p=$1;print;if(p=="uid:")print "cn:"$2}
' /path/to/input < output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top