*update* : simplification with xx_XX.UTF-8 "locale" (see below)
When you are using ldapsearch to find quickly some informations in LDAP directory, there are some problems.
- Some lines are wrapped (several lines for a single attribute-value).
- Some lines are encoded in base64 (those with utf8 content).
For instance, with this command :
ldapsearch -x -LLL -h myldaphost -b 'ou=myldapbase,...'
Just "pipe" the result in this Perl filter :
ldapsearch ... | perl -MMIME::Base64 -MEncode=decode -n -00 -e 's/\n +//g;s/(?<=:: )(\S+)/decode("UTF-8",decode_base64($1))/eg;print' [or] ldapsearch ... | perl -MMIME::Base64 -MEncode=decode -n -00 -e 's/\n +//g;s/(?<=:: )(\S+)/decode("UTF-8",decode_base64($1))/eg;print if /Be +yoncé/'
This way, the Lord of the Rings can see the entire block (LDAP entry) matched by the regex you want (a single lady, in this example).
Warning : the output is NOT LDIF-compatible, it's just 'text'.
update : depending of your context (locale with or without UTF-8), you can simplify the command-line, like this:
ldapsearch ... | perl -MMIME::Base64 -n -00 -e 's/\n //g;s/(?<=:: )(\ +S+)/decode_base64($1)/eg;print' [or] ldapsearch ... | perl -MMIME::Base64 -n -00 -e 's/\n //g;s/(?<=:: )(\ +S+)/decode_base64($1)/eg;print if /Beyoncé/'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Readable ldapsearch output
by i5513 (Pilgrim) on Apr 06, 2012 at 17:09 UTC | |
Re: Readable ldapsearch output
by Anonymous Monk on Jul 25, 2013 at 00:46 UTC | |
Re: Readable ldapsearch output
by Anonymous Monk on Sep 09, 2013 at 19:25 UTC | |
Re: Readable ldapsearch output
by Anonymous Monk on Sep 19, 2014 at 08:14 UTC | |
by Anonymous Monk on Aug 13, 2016 at 18:32 UTC | |
by Anonymous Monk on Aug 13, 2016 at 20:52 UTC | |
Re: Readable ldapsearch output
by Anonymous Monk on Jul 29, 2015 at 12:58 UTC | |
by Anonymous Monk on Sep 03, 2015 at 01:26 UTC | |
by Anonymous Monk on Jan 17, 2018 at 20:33 UTC |
Back to
Cool Uses for Perl