question

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
srive99
Posts: 30
Joined: Fri Apr 16, 2010 1:45 pm

question

Post 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
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
srive99
Posts: 30
Joined: Fri Apr 16, 2010 1:45 pm

question

Post 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.
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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.
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
srive99
Posts: 30
Joined: Fri Apr 16, 2010 1:45 pm

question

Post by srive99 »

Thanks for your reply...

Unfortunately it is not finding the DN's which has special charcters like _ and &, also space.
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
srive99
Posts: 30
Joined: Fri Apr 16, 2010 1:45 pm

question

Post 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
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
srive99
Posts: 30
Joined: Fri Apr 16, 2010 1:45 pm

question

Post by srive99 »

Thanks, That did the trick.
Post Reply