How to fix sed command on MacOS with error extra characters after \ at the end of c command?

Viewed 671

Following sed command works on Linux and Windows but fails on MacOS/BSD:

sed -i '/"appId"/c\  \"appId":\  \"'${applicationId}'\",' $capacitorConfigJson

I tried to add ' ' -e

sed -i ' ' -e '/"appId"/c\  \"appId":\  \"'${applicationId}'\",' $capacitorConfigJson

and then script fail with error:

sed: 1: "/"appId"/c\  \"appId":\ ...": extra characters after \ at the end of c command

I found similar solutions to add newline after c\ but it doesn't seems to work.

1 Answers

Try this on BSD (OSX) sed:

sed -i.bak '/"appId"/c\ 
"appId": "'${applicationId}'",
' "$capacitorConfigJson"

Note that there is a space after c\

Related