3

Scripting/text manipulation help

view full story
linux-howto

http://forums.fedoraforum.org – Hey guys.. I am not sure if this is the right place to post this - but here goes. I need to manipulate an openldap export to match a different schema so that I can import into that system. Basically - its just text manipulation. I have gotten alot of it done just by using simple sed, but I am sorta stuck on the following. here is an example export: dn: mailRoutingAddress=[email protected],ou=People, dc=domain,dc=com changetype: add objectClass: user sn: Smith givenName: Joe cn: Joe Smith telephoneNumber: (304)555-5555 facsimileTelephoneNumber: (304)555-5555 title: LCM 2 uid: joe.smith dn: mailRoutingAddress=[email protected],ou=People,dc= domain,dc=com changetype: add objectClass: user sn: Jones givenName: Jenny cn: Jenny Jones uid: jjones telephoneNumber: (406)555-5555 facsimileTelephoneNumber: (406)555-5555 title: LCM 2 --snip-- There are 4000 of these entries, each with line breakes between them. What I want to do is automate changing of the dn line to get rid of the 'mailRoutingAddress bit and change it to the cn. so once the entries have been 'fixed' they will read like this: dn: cn=Joe Smith,ou=People,dc=domain,dc=com changetype: add objectClass: user sn: Smith givenName: Joe cn: Joe Smith telephoneNumber: (304)555-5555 facsimileTelephoneNumber: (304)555-5555 title: LCM 2 uid: joe.smith dn: cn=Jenny Jones,ou=People,dc=domain,dc=com changetype: add objectClass: user sn: Jones givenName: Jenny cn: Jenny Jones uid: jjones telephoneNumber: (406)555-5555 facsimileTelephoneNumber: (406)555-5555 title: LCM 2 Im a little stumped at how I could do this.. I suppose I could write a for loop to go through and change the dn - but i really havent the slightest idea where to start! Any help would be appreciated. - (HowTos)