in reply to Reformat command output inline

Hi RenMcCourtey,

While what you want to do could be done with a oneliner*, as the code gets more complex it's certainly advisable to use the proper tools for the job.

Apparently ldapsearch outputs in LDIF format, which can be read by, for example, Net::LDAP::LDIF. Here's a quick example I whipped up using the documentation, its output looks like what you want:

use Net::LDAP::LDIF; my $ldif = Net::LDAP::LDIF->new('nejms.txt', 'r', onerror=>'die'); while (!$ldif->eof) { my $entry = $ldif->read_entry; print $entry->get_value('cn'), "=", $entry->get_value('orclnetdescstring'), "\n"; } $ldif->done;

If it's an option for you, you could maybe use Net::LDAP for all your work. (Disclaimer: I don't have experience with the module. It does have a long release history and good reviews, though.)

* I'd strongly recommend the above instead, this is just an example of one way to do it:

$ perl -ne 'next if /^dn:|^\s*$/; s/^cn:\s*(.+)\n/$1/; s/^orclnetdescstring:\s*/=/; print' nejms.txt common_name1=complex_address_line1 common_name2=complex_address_line2 common_name3=complex_address_line3

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Reformat command output inline
by RenMcCourtey (Acolyte) on Jun 29, 2016 at 13:51 UTC
    Thanks a lot for both examples. This is actually what I had on mind in a broader sense, like, if I don't scratch my left ear with my right hand, so to speak. Clearly I did.:-) I'll dig deeper into links you posted now.