I have a sed replacement command that I would like to be compatible with BSD
sed as well as GNU
sed. Extended regular expressions are not an issue as I do not need them in this case. My primary problem is difference in the way that the two
seds interpret character escape sequences in the replacement strings. My replacement string contains tabs and newlines and I'd like them to be visible in the command strings for ease of maintenance, however, BSD
sed doesn't interpret the escape sequences and GNU
sed does. What is the appropriate way to instruct
sed to interpret these escape sequences on BSD? The following two snippets epitomize my problem:
echo ABC | sed 's/B/\n\tB\n'
A B C
echo ABC | sed 's/B\n\tB\n'
\t aren't interpreted as escape sequences by BSD
Now, to my question. According the BSD
To specify a newline character in the replacement string, precede it with a backslash.
Does this imply that I'd need to precede a literal newline by a backslash? What is the appropriate way to instruct
sed to interpret escape sequences like
\n in the replacement text?