So in other words, it
doesn't work perfectly.
Yeah, I seem to have left out some necessary parts. That's what I get for trying to work from memory. Multi-line sed commands can be such a dog to wrap your head around.
So, going back to the
sed faq, here's the full working (hopefully) command:
Code:
sed -r ':a ;$! N; s/\n([^0-9])/ \1/; ta ; P ; D'
The added parts do this:
$! N means it doesn't try to continue on when the last line is reached. The last line doesn't print without it.
P ; D prints out, then deletes, the part of the pattern space before the first newline.
Frankly, I'm still not completely sure what everything is doing. If I'm reading it right, it tries to loop through as many lines as it can, but the loop breaks when it hits a line that contains a digit, or nothing. So whenever the loop terminates, it prints out the first, completed part of the pattern space, and continues to hold on to the last part (the line that caused it to break) for further processing in the next pass.