I would like to replace a string in a line with shell and regex.
For example, in file configuration.php
I would like to replace TO_REPLACE
with OK_REPLACED
:
public $user = 'TO_REPLACE';
I tried this command:
cd ~/public_html; sed -i "s/^public $user = *'[^']*'/1OK_REPLACED'/g" configuration.php
but I get this error
sed: -e expression #1, char 39: invalid reference 1 on `s' command's RHS
I also tried this one but nothing
sed -i "s/^(public $user = *')[^']*'/1OK_REPLACED'/g" configuration.php
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…