It has always bugged me that sed
, which is mostly compatible with ed
, doesn't have the same j
command (to join two lines together) that ed
does. Once upon a time I imagined this was because sed
works exclusively on one line at a time, such that its internal architecture wouldn't be able to cope with a previous and a next line at once. But of course sed
does have its mysterious g
and h
commands, manipulating the equally mysterious "hold space". When I discovered that, I remember imagining that it would surely be possible to use the "hold space" to achieve the more or less the same result as a j
— except it's not, or if it is, it's intricate and difficult.
I asked about this on Stack Overflow one time, and didn't learn much, although I did get a nice Stack Overflowey lecture on why I shouldn't want a j
command in sed
in the first place.
So I ask here. Does anyone have any idea why sed
has never had a j
command? Was it too hard to implement at first? Were the g
and h
commands easier? Is there some reason why a hypothetical j
command was a spectacularly bad idea, or truly impossible to implement?
Me, I can't imagine it would be that hard to implement (certainly no harder than the existing g
and h
), and I'm still sorely tempted to take a stab at it myself, despite the discouragement I received, except I can't believe no one else has done it already, making me suspect that maybe there
is some really good reason not to.
awk
orsed
," and then I ended up doing it with a throwaway C program instead. Then, one day, I discovered Python, and I've never thought to use any other language for filtering text files since.N;s/\n//
is the equivalent ofj
in ed. Or you can do extra work with the hold space, but it is not necessary.