I am trying to add the line text += num.toString(16); after each line, using sed.My approach is: Replace every new line with a new line, plus text += num.toString(16);. That is:sed 's/\/\text \+= num\.toString\(16\);/g'But I couldn't get this working. I am getting unterminated substitute pattern from sed.What is wrong here?I am using BSD sed.
What is wrong with the escaped newline in this sed command?
sed
You can't use:s/\/to match newline in pattern space in s/pattern/replacement/ form. It depends on implementations to interpret that pattern. Both GNU sed and BSD sed treats it as literal newline, but BSD sed doesn't accept and will raise the error.Generally, you can't match a newline at the end of input line, but you can use \n to match newline appears in pattern space as the result of N command.The right way, POSIXLY:sed 'a\text += num.toString(16);'or:sed 's/$/\text += num.toString(16);/'