4

I want to stop sed from adding a newline with the i editing command:

>echo "hello" | sed 'i TEST'
TEST
hello

The result I want is:

TESThello
Pedro
  • 355
  • 4
  • 18

2 Answers2

3

I think it is not possible. Do it this way instead:

sed 's/^/TEST/' file
oguz ismail
  • 1
  • 16
  • 47
  • 69
  • 1
    seems like the `i` and `a` commands can be replaced by `s` most of the times. – Pedro Oct 07 '18 at 23:21
  • 3
    @Pedro They have different purposes. `i` and `a` are to insert and append complete lines before/after the current line. `s` is to make substitutions in the current pattern buffer. There's also `c` that works like `a` and `i`, but replaces ("changes") the whole current line. – Benjamin W. Oct 08 '18 at 02:14
-1

You can try this too:

echo "hello" | sed "s/$/TEST/"

What it is doing is replacing the end of the line (/$/) with the text you want.

Gianluca Mereu
  • 300
  • 1
  • 4