a "trivial" sed question

Leo de Wit leo at philmds.UUCP
Mon Jun 13 15:09:19 AEST 1988


In article <512 at cogen.UUCP> alen at cogen.UUCP (Alen Shapiro) writes:
>I know the answer is 'use tr -d "\012"' but here is the question;
>
>Is there a way USING SED to remove all <NL> chars from a file. This is
 [40 lines deleted]

>From an sed addict:
I don't think this can be done for any size of file. I'll explain:
Whenever sed outputs a line, it has a trailing newline. The best you can
do is thus create one big line containing all lines of the file and remove
newlines from it (all but the last). You already indicated that you can use
N to add to the pattern space. The problem is: this pattern space has of
course a limited size (don't know if it is malloc'ed or just a big buffer)
unless sed swaps this space to the disk (don't think so). Think your core
dump was due to running out of buffer space. If your file is small enough,
you could do:

sed -n -e '
1h
2,$H
${
	x
	s/\n//g
	p
}' your_file

This doesn't need labels (look Ma, no GOTO's! 8-).

	Leo.



More information about the Comp.unix.questions mailing list