Inserting a newline in the middle of a line in ed (editor)

Viewed 1247

Suppose I have opened a text file in ed, and the current line looks like this:

This is sentence one. Here starts another one.

Now I want to put a newline after one. , such that the new sentence starting with Here starts occupies the next line.

How do I do this in ed?

3 Answers

You can do

t.
s/text_before/
-s/text_after/

Explanation:

  1. t. copies the line, in order to get 2 consecutive identical lines, both containing the original text.
  2. Change the 2nd line to contain only the text you want after the added newline.
  3. Do the same, for the 1st line, for text you want before the newline.

NOTE: The '-' prefix means, do it for the previous (of the current addressed) line.

Related