For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2008 > parse x.500 DN and change order displayed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author parse x.500 DN and change order displayed
SecureIT

2008-03-31, 8:29 am

I am trying to change this

"cn=Bob Smith+serialNumber=CR013120080827,o=ICM,
c=US"

to this:

"serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"

There are about 2000 entries like this and I need to have them all
displayed with serialNumber first, and cn last then the rest of the
DN, the names and serialNumbers are all unique to each entry.

Any help would be great

Thanks,
gotsecure

Peter Scott

2008-03-31, 8:29 am

On Sun, 30 Mar 2008 20:36:58 -0700, SecureIT wrote:
> I am trying to change this
>
> "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,
c=US"
>
> to this:
>
> "serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"
>
> There are about 2000 entries like this and I need to have them all
> displayed with serialNumber first, and cn last then the rest of the
> DN, the names and serialNumbers are all unique to each entry.


s/^(cn=.*?)+(.*?),/$2+$1,/;

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

T Baetzler

2008-03-31, 8:29 am

Peter Scott <Peter@PSDT.com> wrote:

> On Sun, 30 Mar 2008 20:36:58 -0700, SecureIT wrote:
=20[color=darkred]
> s/^(cn=3D.*?)+(.*?),/$2+$1,/;


Close, but no cigar ;-)

+ is a quantifier meaning 1 or more matches of the
preceeding expression, so you'll end up with all of
the string up to , in $1 and nothing in $2.

You'll have to escape it to match a literal '+'.

I would also drop the ^ since it is unclear if the
data is indeed without leading whitespace and/or
quotes.

HTH,
Thomas
peter@psdt.com

2008-03-31, 8:29 am

> Peter Scott <Peter@PSDT.com> wrote:
>
>
> Close, but no cigar ;-)
>
> + is a quantifier meaning 1 or more matches of the
> preceeding expression, so you'll end up with all of
> the string up to , in $1 and nothing in $2.


Sigh. Too little sleep.

/^(cn=.*?)\+(.*?),/$2+$1,/;

> I would also drop the ^ since it is unclear if the
> data is indeed without leading whitespace and/or
> quotes.


If it's really a DN as the subject states, both will be true.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com