francoisromain francoisromain - 1 year ago 66
Linux Question

modify a file using a bash script with sed

similar to these questions:

In a file like this:

define('_DB_NAME_', 'anything');
define('_DB_USER_', 'something else');
define('_DB_PASSWD_', 'and another value');

how to use sed to replace the value
(which are unknown) by refering to the key values

Answer Source
sed "s/\(define('_DB_NAME_', \).*/\1'new value');/" filename

and likewise for the other two.

If you want to alter the file in place, you can use -i, but you have to be careful, different versions of sed handle that differently.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download