Search code examples
regexsedbsd

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


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.


Solution

  • In a shell, you can do:

        sed 's/ /\
    /g'
    

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