It is currently Thu, 20 Jan 2022 05:23:50 GMT



 
Author Message
 to all sed hackers - joining lines with sed
hi group!

i have a huge text file with lines that llok like that:

123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon
 (of course the lines differ :)

somethimes in that textfiles ther are errors, there are sometimes
newlines there that should not be, like this:

123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblah
blahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon
123456     blahblahbla      moreblahblahblah    andsoon

what i want now is a sed script, that does the following:

if a line starts with a letter or parenthesis, join it with the
preceeding line. i have managed to do so with this example:

cat test| sed -e :a -e '$!N;s/\n[A-Za-z\(\)]//;ta' -e "P;D"

but the problem is that this deletes the first letter of the wrong row
because of
s/\n[A-Za-z\(\)]//
.

so this:

123456     blahblahbla      moreblah
blahblah    andsoon

results in:

123456     blahblahbla      moreblahlahblah    andsoon
                                                                ^^
there should be a "b"

can i somehow preserve that letter or paste what was deleted but
without the preceeding newline?

big thanks in advance!!



 Mon, 28 Nov 2005 03:25:58 GMT   
 to all sed hackers - joining lines with sed
a.wall...@focusmr.com (armin walland) wrote in
news:6fe02390.0306111125.2e3f66cb@posting.google.com:

It looks like the following works:
cat test| sed -e :a -e '$!N;s/\n\([A-Za-z()]\)/\1/;ta' -e "P;D"

Berend



 Mon, 28 Nov 2005 15:11:06 GMT   
 to all sed hackers - joining lines with sed

Yeeee!!
thank you very much, you're a life saver :)
the sed manpage could really use some examples i think

best wishes, armin



 Tue, 29 Nov 2005 00:49:10 GMT   
 
   [ 3 post ] 

Similar Threads

1. HELP: join lines with sed .....

2. sed 'Joining lines'?

3. Sed one liner (!?) for joining lines

4. Sed: How to join lines back

5. joining lines in sed

6. sed, join indented lines?

7. sed sed sed

8. SED SED SED...

9. . 2 sed FAQs, sed exes, sed cetras; URLs


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software