How to insert a newline in front of a pattern?

This works in bash and zsh, tested on Linux and OS X: sed ‘s/regexp/\’$’\n/g’ In general, for $ followed by a string literal in single quotes bash performs C-style backslash substitution, e.g. $’\t’ is translated to a literal tab. Plus, sed wants your newline literal to be escaped with a backslash, hence the \ before … Read more