Results 1 to 3 of 3
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 ...
- 07-08-2011 #1Just Joined!
- Join Date
- Jul 2011
- Posts
- 2
remove leading space and join previous line
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 line
i 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
- 07-11-2011 #2Just Joined!
- Join Date
- Nov 2006
- Posts
- 2
A Solution
Perl seems like an obvious tool for this. Here is a rough hack that may get you started. Put this on the command line:
p.s. I'm not a programmer, so forgive any bad style.Code:perl -ne 'use feature "state"; state $join_it=0; if ($join_it==1) { if (s/^ //) { print } else { print "\n" }; $join_it=0 }; if (/^dn:/) { chomp; print; $join_it=1 }' dn_file
- 07-13-2011 #3Just Joined!
- Join Date
- Jul 2011
- Posts
- 2
ty vamped1.
in the meantime i got a solution which is more compact and is exactly what i need.
for everyones interest:
sed -e :a -e '$!N;s/\n //;ta' -e 'P;D' filename
br, iko


Reply With Quote