3

I am trying to replace the string

: 'development'

with

: 'production'

using sed.

I tried a few options including:

sed -i "s|: \'development\'|: \'staging\'|g" index.php

but without any luck. Output:

sed: 1: "index.php": command i expects \ followed by text

Can someone help?

5

You don’t need to escape single quotes inside double quotes, see this answer of mine:

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, and, when history expansion is enabled, !.

Thus, these work:

sed -i "s/: 'development'/: 'staging'/g" index.php
sed -i "s|: 'development'|: 'staging'|g" index.php
sed -i 's|: '\''development'\''|: '\''staging'\''|g' index.php
2

I suggest:

sed "s/: 'development'/: 'production'/" index.php`
0

I managed to sort it out. Turned out in mac machine I have to postfix .bak with -i. But in Linux it worked without it. I was first trying it in my local machine to see the output and it was failing.

Thank you all for your help.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.