Skip to main content
added 211 characters in body
Source Link

To preserve the leading spaces when inserting a variable, you just have to escape once the spaces with a backslash \ after the insert command i, like this:

$ sed '50i\'"$add" file
    public function add($hardware_id = null)

  1. Is not specific to variables, it would be the same if the text was inserted literally.

  2. Is not a POSIX specified behavior, which mandates a escaped literal newline before the text to be inserted.

To preserve the leading spaces when inserting a variable, you just have to escape once the spaces with a backslash \ after the insert command i, like this:

$ sed '50i\'"$add" file
    public function add($hardware_id = null)

To preserve the leading spaces when inserting a variable, you just have to escape once the spaces with a backslash \ after the insert command i, like this:

$ sed '50i\'"$add" file
    public function add($hardware_id = null)

  1. Is not specific to variables, it would be the same if the text was inserted literally.

  2. Is not a POSIX specified behavior, which mandates a escaped literal newline before the text to be inserted.

Source Link

To preserve the leading spaces when inserting a variable, you just have to escape once the spaces with a backslash \ after the insert command i, like this:

$ sed '50i\'"$add" file
    public function add($hardware_id = null)