• Uncategorized

About linux : sed–i-doesent-work-on-MacOs-sed-1-and-work-on-linux-duplicate

Question Detail

I succeeded to use sed -i on Linux to modify a JSON value in a file.

$> sed -i '/brand/c\   \"brand\": \"'valueModified'\"' ./config/brand.config.json

But on MacOS I get:

sed: 1: “./config/brand.config.json”: invalid command code .

I’m trying to use this command in a shell script on linux and macOS.

Thank you

Question Answer

POSIX sed implementations allow for the I line replacement where non-POSIX UNIX implementations do not. OSX, like BSD implentations can be accomplished like so :

cp -p ./config/brand.config.json ./config/brand.config.json.tmp;
sed '/brand/c\   \"brand\": \"'valueModified'\"' ./config/brand.config.json.tmp > ./config/brand.config.json

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.