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?
sed (GNU sed) 4.2.2– Mohammed Noureldin Sep 12 '17 at 11:21sed -r '/utf8_filesystem/a\\n# Passive mode'should also work. – anubhava Sep 12 '17 at 11:35sed -r 's/utf8_filesystem/&\n\n# Passive mode/'– anubhava Sep 12 '17 at 11:48\n-> I would expect new line, but it is not. it needs to be\\\nto work, why is this? or in case of using single quotes, see please my comment bellow in RedGrittyBrick answer. – Mohammed Noureldin Sep 12 '17 at 13:27sed -r -e '/utf8_filesystem/a' -e '\n# Passive mode' <<<'one utf8_filesystem two' sed: -e expression #1, char 18: expected \ after 'a', 'c' or 'i'. See whatinfo sedsays abouta,candicommands. This is what I understand of the problem, I don't know if it is the right answer. – Paulo Sep 12 '17 at 19:18