tags:

views:

264

answers:

1

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.

+2  A: 

In a shell, you can do:

    sed 's/ /\
/g'

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

Wooble
Fantastic, thanks Wooble. Is there any known reason why BSD sed doesn't support \n in the replacement string? Just curious.
Brett Ryan
I'm not sure, but it seems they just decided to not support escapes at all in the replacement string.sed 'y/ /\n/' seems to work, although it only does string replacement; if you need to replace the ' ' with a regex it will fail. Also, the \n seems to be special-cased; \r with get you an 'r', not a carriage return.
Wooble