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?

0

3 Answers 3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .