sed find and replace a string with spaces

bash, linux, regex, replace, sed

Solution

Try this:

sed -i -e "s/public\s\$password\s=\s'\(.*\)'/private \$password = 'jingle'/" configuration.php

The problem was that you need to 'escape' the round brackets, and that `\s` doesn't work in the output pattern. You also had missed the final `/`.

Problem

Having the following in a file: ``` public $password = 'XYZ'; ``` I'm trying to replace the password's value with a different one, through an automated deployment process from backup files. I have the regext that will match the string above in a file, but not much compatible with `sed` ``` (public\s\$password\s=\s'(.*)'?) ``` I also tried ``` sed -i -e "s/public\s\$password\s=\s'(.*)'/private\s\$password\s=\s'jingle'" configuration.php ``` Any ideas?

Original source