0

Reading sed manual, It seems only \ and & are to be watch out for in replacement space when using the s command in sed.

Are there any other characters having special meaning in replacement space? (Affecting the replacement)

Ravi Saroch
  • 934
  • 2
  • 13
  • 28

1 Answers1

0

Short Answer: You need to quote '\' '&' and new line.

Long Answer: The 'sed' man page indicates

   To include a literal '\', '&', or newline in the final replacement,
be sure to precede the desired '\', '&', or newline in the REPLACEMENT
with a '\'.

Implying all other characters are valid literals in the REPLACEMENT string.

dash-o
  • 13,723
  • 1
  • 10
  • 37
  • If \ is quoted, \n is therefore Quoted too at that point. Does "newline" mean something else in the answer(s)? –  Oct 01 '19 at 09:44
  • @DegenWoW - newline refers to "simple" new line, which can not be placed into the REPLACEMENT part. If you do not quote it, it will be interpreted as the end of a sed command. In other words, you can not type 's/A//' (it will produce 'unterminated 's' command). As you have indicated, you can use \n to force a newline to the REPLACEMENT – dash-o Oct 01 '19 at 09:52