sed script to remove cr/lf except at paragraph breaks

Roger A. Cornelius rac at sherpa.UUCP
Fri May 19 12:26:55 AEST 1989


I'm in need of a sed script to remove MSDOS cr/lf (actually replace each
cr/lf combination with one space) except at the start of a paragraph.
i.e. only the cr/lf preceding a paragraph break should remain.  Paragraphs
are marked only by four leading spaces and nothing else.

Here's where I am now:

N
h
/\n    /{
P
D
}
s/^M\n/ /g

This works correctly for the first match, ie beginning of a paragraph,
but for all other lines, the substitution of a space for cr/lf only
works correctly for the first occurrance in the line (the g flag seems
to have no effect).  But there are two occurrances due to the N function.
How can I match (and substitute for) the terminating nl in the pattern
space?  The sed man pages concerning addresses say you can't.  What am
I missing or how can I get around this?

This is probably simple and has been covered here before.  Sorry.

Any help appreciated.
Roger



More information about the Comp.unix.questions mailing list