1

I've got a problem and I am not sure whether this is a bug or if this is supposed to happen when using $ for addressing lines. Basically, I have the following command:

sed -e '$s/test/tset/g'

Usually, I would expect it to run like this:

blahblah
blahblah
  <-- Cursor is here now

Meaning: I type in something and press Enter one time, and the result is shown in the next line, However, instead I get the following:

blahblah

blahblah
  <-- Cursor is here now.

So, basically the $-symbol seems to somehow cause sed to set the cursor to an empty line and only after I press enter again, it actually shows the result (means: I have to press Enter two times). Is there any way to prevent that or is this possibly a bug? In my more complex patterns this is actually messing up a lot of stuff.

  • 2
    It has no way to know whether this is the last line until either the input ends or it gets a subsequent line. What are you expecting the command to do (aside from the cursor positioning)? – Michael Homer Jun 28 at 7:31
3

Since sed knows it will have to apply a command to the final line of input, it can't output the most recently processed line until it's sure it can read more lines after that.

You would not see the same behaviour in a sed editing script not using the $ address, as the transformation of the data does not depend on whether the current line is the final line of input or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.