With a little side of applesauce...

Friday, November 14, 2008

PERL - fix LDAP exports with line breaks

Thanks to this posting, by Dan Norris, we now have an easy script to fix the line breaks which are inserted by phpLDAPAdmin exports. (Apparently, ldapsearch does the same thing).
$cnt=0;
while ($line = <>) {
chomp($line);
if ( $line =~ /^authpassword/ ) {
next;
} elsif ( $line =~ /^\S+/) { ### this line is a "normal" or starting line
$results[$cnt++] = $line;
} elsif ( $line =~ /^$/ ) { ### this line is blank
$results[$cnt++] = "";
} elsif ( $line =~ /^ \S+/ ) { ### this line is a continuation
$results[$cnt-1] = $results[$cnt-1] . substr($line,1);
}
}

for $i (0 .. $cnt) {
print "$results[$i]\n";
}

1 comment:

Dan Norris said...

Glad it is helpful. Let me know if you find any good enhancements for it!