Currently I’m trying to create a bash script for replacing new values I generated.
These values were stored in constants.php:
-----------constant.php : start-------------------
:
define('PASS1', 'ABCD');
define('PASS2', '1234');
:
-----------constant.php : end---------------------
After running script, (using sed) it should update the values of PASS1 and PASS 2 separately:
-----------constant.php : start-------------------
:
define('PASS1', 'WXYZ');
define('PASS2', '0987');
:
-----------constant.php : end---------------------
Is there a way I can find the KEY e.g. 'PASS1' and replace the values after the comma?
You can specify the occurrence with
sedsosed "/PASS1/s/'[^']*'/'WXYZ'/2"matches any lines containingPASS1and does the following substitutions/'[^']*'/'WXYZ'/2which: