sed always removes the trailing
\newline just before populating pattern space, and then appends one before writing out the results of its script. A
\newline can be had in pattern-space by various means - but never if it is not the result of an edit. This is important -
sed's pattern space always reflect a change, and never occur in the input stream.
\newlines are the only delimiter a
sedder can count on with unknown input.
If you want to replace all
\newlines with commas and your file is not very large, then you can do:
That appends every input line to
hold space - except the first, which instead overwrites
hold space - following a
\newline character. It then
deletes every line not the
$!last from output. On the last line
Hold and pattern spaces are e
xchanged and all
\newline characters are
y///translated to commas.
For large files this sort of thing is bound to cause problems -
sed's buffer on line-boundaries, that can be easily overflowed with actions of this sort.