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

Brett Ryan picture Brett Ryan · Sep 14, 2009 · Viewed 10.9k times · Source

Greetings, how do I perform the following in BSD sed?

sed 's/ /\n/g'

From the man-page it states that \n will be treated literally within a replacement string, how do I avoid this behavior? Is there an alternate?

I'm using Mac OS Snow Leopard, I may install fink to get GNU sed.

Answer

Wooble picture Wooble · Sep 14, 2009

In a shell, you can do:

    sed 's/ /\
/g'

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