LDAP LDIF Perl search script

Problem

You want to search an LDIF file for a given dn, or pattern.



Solution

Multi-line pattern search and output – useful for LDIFs! 😉

Written in Perl – see example tab.



Example


Replace pattern to a given name, etc and filename to LDIF output file.

perl -ane '$/="dn" ;

print,"\n\n" if($_ =~/pattern/);' filename

For example:


$ cat user.ldif
dn: cn=user0,dc=subdiv,dc=demo,dc=net
objectClass: person
sn: User
cn: user0
userPassword: today321

dn: cn=user1,dc=subdiv,dc=demo,dc=net
objectClass: person
sn: User
cn: user1
userPassword: today321

$ perl -ane '$/="dn" ;
print,"nn" if($_ =~/user1/);' user.ldif

: cn=user1,dc=subdiv,dc=demo,dc=net
objectClass: person
sn: User
cn: user1
userPassword: today321



Reference

[tags]LDAP LDIF Search, LDAP LDIF extraction, LDAP Training School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *