If you want to play with shell and ldapsearch output, be sure your dn entries are one per line. A perl script could be: ldapsearch ... | perl -p -0040 -e 's/\n //'