How do I use a new-line replacement in a BSD sed?

In a shell, you can do:

    sed 's/ /\
/g'

hitting the enter key after the backslash to insert a newline.


Another way:

sed -e 's/ /\'$'\n/g'

See here.


For ease of use, i personally often use

cr="\n" 
# or (depending version and OS)
cr="
"

sed "s/ /\\${cr}/g"

so it stays on 1 line.