Page 1 of 1
question
Posted: Fri Sep 17, 2010 8:39 pm
by srive99
hi all,
I'm going to need to work a lot with texpad and I need some help with it. I have bunch (thousands)of ldap dns like below
dn: cn=abc, ou=xyz, o=org
and I want to add couple of lines to those each dns like below
dn: cn=abc, ou=xyz, o=org
objectClass: user
objectClass: Top
Also, I need to grab the cn value from each dn and put it separate line for each dn and it should be like below
dn: cn=abc, ou=xyz, o=org
objectClass: user
objectClass: Top
cn=abc
dn: cn=qwer, ou=xyz, o=org
objectClass: user
objectClass: Top
cn=qwer
I know we can do this with texpad but dont know how I can do that. Thanks
Posted: Sat Sep 18, 2010 2:06 pm
by Mike Olds
Hello,
Try this:
>Search>Replace
Search:
dn: cn=\([a-zA-Z0-9 .:/-]*\), ou=\([a-zA-Z0-9 .:/-]*\), o=\([a-zA-Z0-9 .:/-]*\)
Replace with:
dn: cn=\1, ou=\2, o=\3
objectClass: user
objectClass: Top
cn=\1
Ben will probably be able to come up with something simpler, but I believe this will do the job
question
Posted: Sat Sep 18, 2010 4:33 pm
by srive99
it works great. Thanks.
But I found some thing that this regular expression does not work if "dn" has some speacial charcters like below.
dn: cn=abc xyz_qra, ou=myorg,o=org
dn: cn=ab xy lcp & bt -grp,ou=myorg,o=org
dn: cn=xy bmn as & ss & ss-feo,ou=myorg,o=org
I think, I would need everything until first comma (,) for the cn value regardless of special charcters, spaces, numbers..etc.
Posted: Sat Sep 18, 2010 7:11 pm
by Mike Olds
You can add your special characters in the bits that look like this:
\([a-zA-Z0-9 .:/-]*\)
e.g., to add the underscore:
\([a-zA-Z0-9 .:/-_]*\)
Your example above has no space between
ou=myorg,o=org
I presume you will make the change for that.
question
Posted: Mon Sep 20, 2010 9:07 pm
by srive99
Thanks for your reply...
Unfortunately it is not finding the DN's which has special charcters like _ and &, also space.
Posted: Tue Sep 21, 2010 11:25 am
by Mike Olds
The below works for me in this case:
dn: cn=a_bc, ou=x yz, o=o&rg
If this does not fit your situation you need to give more examples.
dn: cn=\([a-zA-Z0-9 &.:/-_]*\), ou=\([a-zA-Z0-9 &.:/-_]*\), o=\([a-zA-Z0-9 &.:/-_]*\)
Search>Replace
Match Case
Regular Expression
question
Posted: Tue Sep 21, 2010 2:02 pm
by srive99
Thanks for your reply,
it still not working for me. It says "can not find regular expression". I tried with whole DN and also with only CN part.
Thanks
Posted: Tue Sep 21, 2010 4:53 pm
by ben_josephs
Find what: dn: cn=([^,]*).*
Replace with: \0\nobjectClass: user\nobjectClass: Top\ncn=\1
[X] Regular expression
Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
question
Posted: Thu Sep 23, 2010 8:52 pm
by srive99
Thanks, That did the trick.