Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed find and replace a string with spaces

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?

like image 325
Alex Avatar asked Sep 03 '25 10:09

Alex


1 Answers

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 /.

like image 180
ams Avatar answered Sep 04 '25 23:09

ams