hello community! i have a text file (it`s a ldif export), and i would like to grep out the dn. the line with the dn starts with "dn:". no problem so far to grep for this pattern.
but the ldif export makes a line break after 76 characters, and continues the next line with a "space" character.since i need the full dn, i need a way to:
1) search for this lines which start with a leading "space"
2) remove this "space"
3) and finally join the line which had the space, with the previous linei have tried several ways with sed, awk, tr, ... but since i´m quite new to this topics i dont get it solved. does anyone here have a hint for me, how to do this task?
thanks in advance,
iko
With this sed script, if the line starts with a blank space, eliminate the space and append it to the previous line:
sed -e :a -e '$!N;s/\n //;ta' -e 'P;D' datafileIt does NOT check if the previous line starts with dn.
This is a mod of a script from Eric Pement's sed one-liners:
http://www.pement.org/sed/sed1line.txt
Let me know if you have any questions.
wow, thank you nails.
i have no clue how, but it works perfectly for my needs.
i´ll try to understand later on.
and thanks for the link to erics page *bookmarked*
i´m sure it will be of use in future.
thanks again and best regards
You are welcome. Eric's one-liners are explained at this link: http://www.catonmat.net/blog/sed-on...
Look at explanation #40 for the explanation of this particular script.
This didn't work for me on Mac OS X (FreeBSD tools).
The following one liner did though:sed -n -e :a -e '/^$/d;$!N;s/\n //;ta' -e p -e 's/^dn:/\ndn:/' example.ldif
It will break the BASE64 encoding of binary attributes though (eg jpegPhoto).
