Parse x.500 DN and change order displayed

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
SecureIT [ Mo, 31 März 2008 05:38 ] [ ID #1933260 ]

Re: Parse x.500 DN and change order displayed

>>>>> "S" == SecureIT <gotsecure [at] gmail.com> writes:

S> I am trying to change this
S> "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US"

S> to this:

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

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

are all the entries separated by +? how many are there (you show only 2)?

if it is always + then you can just split the lines, grab out the cn one
(use grep) and also filter out the rest. then order them as you
want. call join '+' to rebuild the line. it can also be done with a hash
but that is about the same amount of code.

uri

--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
Uri Guttman [ Mo, 31 März 2008 06:09 ] [ ID #1933262 ]

Re: Parse x.500 DN and change order displayed

SecureIT writes:
> 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"

Without escape sequences like "\," and "\+" in the DNs (if that's
allowed anyway, I don't remember the details of X.500 Dn syntax), this
moves serialNumber first in each RDN:

s/(^|,)([^,]*)\+(serialNumber=[^+,]*)(?=[+,])/$1$3+$2/gi;
die "didn't catch all 'foo+serialNumber's" if /\+serialNumber=/i;

--
Hallvard
Hallvard B Furuseth [ Mo, 31 März 2008 14:26 ] [ ID #1933277 ]
Perl » comp.lang.perl.misc » Parse x.500 DN and change order displayed

Vorheriges Thema: FAQ 8.6 How do I check whether input is ready on the keyboard?
Nächstes Thema: Sharing a DBI::Mysql database connection with your children