Bash: How can I replace a string by new line in osx bash?

bash, sed

Solution

Here is using sed

echo "Replace <newLine> it by <newLine> NEWLINE <newLine> in my OSX terminal <newLine> and bash script" | sed 's/<newLine>/\'$'\n/g'

And here is a blogpost explaining why - https://nlfiedler.github.io/2010/12/05/newlines-in-sed-on-mac.html

Problem

I am googling it a lot. I only want that this line: ``` echo "Replace <newLine> it by <newLine> NEWLINE <newLine> in my OSX terminal <newLine> and bash script" | sed -e 's/<newLine>/\n/g' ``` works in my osx terminal and in my bash script. I can't use `sed` for this? Is there another one line solution?

Original source