sed to remove newlines?

228-4197,ATTT rbr at bonnie.ATT.COM
Sat Jun 1 02:31:00 AEST 1991


In article <6356 at iron6.UUCP> yeates at motcid.UUCP (Tony J Yeates) writes:
>Is it possible to remove newlines (i.e. \n) from a file using sed?  If
>so how?  We have tried various things without success:
>
>escaping \n -> \\n
>double escaping \n -> \\\n
>using \012
>
>but with no success.  Our man page incs. the following:-
>
>"\n   Matches a NEWLINE embedded in the pattern space. "
>
>If this can only be used for pattern matching but not exchange, it would seem
>to offer nothing over the use of $.
>
>[Our current requirement is to concatenate any lines ending with a ':' to  the
>next line in a file.   Although I can think of numerous other uses ( we
>usually end up using tr '\012' '<some char.>' as a work around).]

On input "sed(1)" converts the lint to a string. Therefore, the edit
functions never see the "\n" newline character. I think you may have
the wrong focus to solve the problem, think joining selected lines,
not eliminating newlines.

Why not use "ed(1)" as:

cp $1 $2
ed - $2 \\E-O-C
g/:$/j
w
q
E-O-C

Bob Rager



More information about the Comp.unix.shell mailing list