[problem]
You want to search an LDIF file for a given dn, or pattern.
[/problem]
[solution]
Multi-line pattern search and output – useful for LDIFs! 😉
Written in Perl – see example tab.
[/solution]
[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
[/example]
[reference]
[tags]LDAP LDIF Search, LDAP LDIF extraction, LDAP Training School[/tags]
[/reference]
If you have found my website useful, please consider buying me a coffee below 😉