Skip to main content

linux - sed needs `\n` to append new line

I am trying to append a new line using sed, it works only when I add the new line like this: \\\n:


echo "sometextutf8_filesystemmmmm" | sed -r "/utf8_filesystem/a \\\n# Passive mode"

the output:


sometextutf8_filesystemmmmm

# Passive mode

One or two back slashes do not work! With one \n or two \\n back slashes I just get this output:


sometextutf8_filesystemmmmm
n# Passive mode

without any new line.


Even though, it works properly without having three backslashes with substitution:


echo "sometextutf8_filesystemmmmm" | sed -r "s/utf8_filesystem/\n# Passive mode/"

Output:


sometext
# Passive modemmmm

Could some one explain that behavior?

Comments