# Simple sed script to remove line breaks between paragraphs
# and to strip lwsp at the start of a line ...
# (c) James Aylett 1999. License: GPL.

# For the first line, don't worry about clearing out the hold space
1 b skip_blank_lines

# If the line is blank, we want to do some stuff to it ...
/^$/! b done_blank_lines

# Clear the pattern space
s/^.*$//
# Append a blank line to the hold space
H
# Print out the hold space - 'x' means that hold space is cleared also ...
x
# Use 'n' so we get the next line of input into the pattern space
n

:skip_blank_lines
/^$/! b done_blank_lines
# Prints out the pattern space and gets the next line ...
n
b skip_blank_lines

:done_blank_lines

# Okay, so strip spaces from the start of this line ...
s/^[[:space:]]*\([^[:space:]]\)/\1/
# And append it to the hold space, preceded by a '\n'
H
# Put the contents of the hold space into the pattern space
g
# Kill that '\n' (don't go overboard on spaces)
s/^\n//
s/ \?\n/ /
# Put the pattern space back into the hold space ...
h
# If this was the last line in the file, print out the hold space
# and leave it at that.
$ x
$ p
$ d

# Delete pattern space, and go on to the next line ...
d
