Newline doesn't work in Sed on Mac OS X

1555 ワード

'' in the replace pattern in sed command doesn't work in Mac OS X.
On Debian, we can get bellowing result:
root# echo abc | sed 's/[^
]/&
/g
' a b c
root#

 
But on Mac, it goes like this:
user$ echo abc | sed 's/[^
]/&
/g
' anbncn user$

 
Solution is to add\'$' before as bellowing:
user$ echo abc | sed 's/[^
]/&\'$
'
/g' a b c
user$

 
Please refer to  http://superuser.com/questions/307165/newlines-in-sed-on-mac-os-x for more detail discussion.
But i tried another method sed 's/[^]/&\\/g' metioned in the discussion, it didn't work on my machine.