[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: slapcat generate extra "space" characters in LDIF output



FWIW, I use this script to undo the line-folding of LDIF.  Just pipe
the output of slapcat or ldapsearch or whatever through it and you'll
get something that's no longer RFC-compliant LDIF but is more amenable
to processing with text-based tools.

#!/usr/bin/perl
# Unfold LDIF so that each attribute is on a single line
my $acc;
while (<>) {
    chomp;
    if (s/^ //) {
        $acc .= $_;
    } elsif (/^\S/) {
        print "$acc\n" if $acc;
        $acc = $_;
    } elsif (/^$/) {
        print "$acc\n" if $acc;
        print "$_\n";
        $acc = undef;
    }
}
print "$acc\n" if $acc;

Refolding is a one-liner, something like this:

    perl -pe 's/^(.{76})(..*)$/$1\n $2/'