0

I have an ldif export where I want to build an outputfile with one line per ldif entry; the one line contains various attribute-values in a specific order.

So the commands should parse each ldif entry beginning with the dn: attribute and evaluate various attributes, extract their values, and then print a delimited line to an outputfile (e.g., uid|cn|sn|givenName|building|title|manager --- like this).

Linux commands or perl will work, thanks for your ideas.

Richard
  • 21
  • 1
  • 3

1 Answers1

1

Write a Perl script using a existing module to parse LDIF (e.g. Net::LDAP::LDIF) and print as desired.

Example:

use 5.012;
use Net::LDAP::LDIF;

my $ldif = Net::LDAP::LDIF->new( "file.ldif", "r", onerror => 'undef' );

while ( not $ldif->eof ) {

  my $entry = $ldif->read_entry;

  if ( $ldif->error ) {
    say "Error msg: ", $ldif->error;
    say "Error lines:\n", $ldif->error_lines ( );
  }

  say(join('|',
    $entry->get_value('uid'),
    $entry->get_value('cn'),
    $entry->get_value('sn')
  ));

}

$ldif->done;
sborsky
  • 315
  • 1
  • 6
  • don't have root to install the module, that's a different problem...so are you saying, (e.g. say(join('|',$entry->get_value('uid'),join('|',$entry->get_value('title'),join('|',$entry->get_value('cn'),join('|',$entry->get_value('sn'),join('|',$entry->get_value('givenName'),...))). What about those values that are embedded in a string...thank you. – Richard Oct 30 '17 at 21:06
  • You don't have to be root, but can install the module in a directory writable for your user. About your second question: 'embedded in a string': What 'embedded values'? – sborsky Oct 31 '17 at 05:05