bt707
asked on
Perl parse dump file
I have a file that has a dump of user records like an example below, each set of user records is separated by a \n (blank line)
I need to read the file in paragraph mode (usually use perl -n00e, but then check to see if each record contains a manager or managerfunctional attribute such as:
manager: CN=Juan Alcocer 494219,ou=employee,o=abc,c =AN
manager: JAlcocer
managerFunctional: JAlcocer
if the record contains a manager or managerfunctional I need to pull out the attributes of
(dn: id: alias: manager and managerfunctional)
I have a issue where some of the attributes for the manager or managerfunctional does not start with a CN=
Example:
Should be such as:
manager: CN=Juan Alcocer 494219,ou=employee,o=abc,c =AN
NOT:
manager: JAlcocer
What I really need to do is pull out only if a record contains a manager or managerfunctional that doe not have the CN= in it but if I can get all of them then I can parse that.
I'm using a one liner such as below and works for the most part but does not give me just what I want.
Any suggestions how I can parse the file to get what I want from each record, need to get the attributes needed all one on line separated by a TAB so I can pull it up in an xls file.
Example of one of the records in the file, all records are separated by a blank line, the records a longer, I just removed some of the attributes to shorten the example, but still all the same, just has more attribuets in them.
Some of the records has multiple lines for the manager or managerfunctional which is what is giving me problems, I don't get all the lines when there is multiple manager or managerfunctional lines.
Example of one of the records in the dump file:
dn: CN=Jeffrey Doe 492919,ou=employee,o=SLB,c =AN
modifyTimestamp: 20120727165756Z
modifiersName: cn=ldap admin 100000,ou=role,o=slb,c=an
adminText: QMM:ADmigrated 2012-4-11
lastModifiedBy: using special rights
lastModifiedOn: 20120727
manager: CN=Juan Alcocer 494219,ou=employee,o=SLB,c =AN
manager: JAlcocer
securityStatus: Training:Level2:20110804
securityStatus: Training:Level1:20110804
securityStatus: QandA:20110916
securityStatus: Password:20120514:good
managerFunctional: JAlcocer
emergencyContactsSaved: Declined
emergencyContactsSaved: 20120322
street: 6213 W County Rd 112
ou: Shared Servicest
languages: Englishns
jobCategory: Engineering
jobCategory: Operations (Field)
c: US
givenNameLegal: Jeffrey07
objectClass: inetOrgPerson
objectClass: slbAdmin
objectClass: slbOrgPerson
objectClass: slbHomePerson
objectClass: organizationalPerson
objectClass: top
objectClass: person
ID: 492919
alias: JDoe
cn: Jeffrey Doe
cn: Jeffrey Doe 492919
displayName: Jeffrey Doe
employeeID: O998807
employeeType: employeen
createTimestamp: 20100826084448Z
Thanks,
I need to read the file in paragraph mode (usually use perl -n00e, but then check to see if each record contains a manager or managerfunctional attribute such as:
manager: CN=Juan Alcocer 494219,ou=employee,o=abc,c
manager: JAlcocer
managerFunctional: JAlcocer
if the record contains a manager or managerfunctional I need to pull out the attributes of
(dn: id: alias: manager and managerfunctional)
I have a issue where some of the attributes for the manager or managerfunctional does not start with a CN=
Example:
Should be such as:
manager: CN=Juan Alcocer 494219,ou=employee,o=abc,c
NOT:
manager: JAlcocer
What I really need to do is pull out only if a record contains a manager or managerfunctional that doe not have the CN= in it but if I can get all of them then I can parse that.
I'm using a one liner such as below and works for the most part but does not give me just what I want.
cat dump.ldif | perl -MMIME::Base64 -n00e 'BEGIN{@attrs=qw{ id alias admintext manager managerfunctional};print join(qq{\t},@attrs),qq{\n}};if(/^manager(|functional): [^c][^n][^=]/mi ){s/\n //g;foreach $a (@attrs){s/^($a:): *(.+)/$1.q{ }.decode_base64($2)/mieg;print q{"},join(qq{\n},m/^$a: (.+)/mig),qq{"\t}}print qq{\n}}'
]Any suggestions how I can parse the file to get what I want from each record, need to get the attributes needed all one on line separated by a TAB so I can pull it up in an xls file.
Example of one of the records in the file, all records are separated by a blank line, the records a longer, I just removed some of the attributes to shorten the example, but still all the same, just has more attribuets in them.
Some of the records has multiple lines for the manager or managerfunctional which is what is giving me problems, I don't get all the lines when there is multiple manager or managerfunctional lines.
Example of one of the records in the dump file:
dn: CN=Jeffrey Doe 492919,ou=employee,o=SLB,c
modifyTimestamp: 20120727165756Z
modifiersName: cn=ldap admin 100000,ou=role,o=slb,c=an
adminText: QMM:ADmigrated 2012-4-11
lastModifiedBy: using special rights
lastModifiedOn: 20120727
manager: CN=Juan Alcocer 494219,ou=employee,o=SLB,c
manager: JAlcocer
securityStatus: Training:Level2:20110804
securityStatus: Training:Level1:20110804
securityStatus: QandA:20110916
securityStatus: Password:20120514:good
managerFunctional: JAlcocer
emergencyContactsSaved: Declined
emergencyContactsSaved: 20120322
street: 6213 W County Rd 112
ou: Shared Servicest
languages: Englishns
jobCategory: Engineering
jobCategory: Operations (Field)
c: US
givenNameLegal: Jeffrey07
objectClass: inetOrgPerson
objectClass: slbAdmin
objectClass: slbOrgPerson
objectClass: slbHomePerson
objectClass: organizationalPerson
objectClass: top
objectClass: person
ID: 492919
alias: JDoe
cn: Jeffrey Doe
cn: Jeffrey Doe 492919
displayName: Jeffrey Doe
employeeID: O998807
employeeType: employeen
createTimestamp: 20100826084448Z
Thanks,
cat fulldump.ldif | perl -MMIME::Base64 -n00e 'BEGIN{@attrs=qw{ id alias admintext manager managerfunctional};print join(qq{\t},@attrs),qq{\n}};if(/^manager(|functional): [^c][^n][^=]/mi ){s/\n //g;foreach $a (@attrs){s/^($a:): *(.+)/$1.q{ }.decode_base64($2)/mieg;print q{"},join(qq{\n},m/^$a: (.+)/mig),qq{"\t}}print qq{\n}}'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,