sed find and replace a string with spaces

11,398

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

Share:
11,398
Alex
Author by

Alex

Why stop learning?

Updated on June 04, 2022

Comments

  • Alex
    Alex almost 2 years

    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?