1829378 Members
4912 Online
109991 Solutions
New Discussion

Re: join lines together

 
SOLVED
Go to solution

join lines together

On RH 6.1 with ldapsearch (openldap -1.2.7-2 I extract entries from my ldap database. As some entries are very long, they are splitted in 2 lines. The format of output file Myfile.ldif is like in the attachment:

I recognize splitted lines because they are preceded by a " " so that
$grep -B1 "^ " Myfile.ldif gives me all couples of lines to join together [Never 3 lines to join!].

At the end I would like to have the same file Myfile.ldif with this problem solved. :))

Thank You in advance!
Leo.
2 REPLIES 2
John Poff
Honored Contributor
Solution

Re: join lines together

Hi,

I played with solving this problem with sed for a while. I gave up and went to Perl. I couldn't find an elegant solution so I went back to sed and finally came up with this:

sed -e :a -e '$!N;s/\n / /;ta' -e 'P;D' Myfile.ldif

See if that does what you want.

JP
Hein van den Heuvel
Honored Contributor

Re: join lines together

perl -e 'while (<>){chop;if (/^ /){print $'}else{print "\n$_"}}print "\n"' tmp.txt

a possibly perl solution. Not too pretty...

- loop over data
- chop of trailing new-line
- if starts with a space then print $' = the rest.
- else print a new-line to finish last line and print this line.
- at end of loop print final new-line.

Hein.