To find the lines in TheFile
that starts with the word power
followed by some amount of whitespace and an equal sign, and to replace whatever comes after that equal sign with something
:
sed -E 's/^(power[[:blank:]]*=[[:blank:]]*).*/\1something/' TheFile
[[:blank:]]*
matches zero or more spaces or tabs. This preserves the whitespace before and after the =
. The \1
in the replacement text will insert the part of the string that is matched by the first parenthesis.
To make the change in place with e.g. GNU sed
, add the -i
flag, otherwise, redirect the output to a new file.
Testing it:
$ cat TheFile
power = 1
power123 = 1
power 123 = 1
power =
power = 112
$ sed -E 's/^(power[[:blank:]]*=[[:blank:]]*).*/\1something/' TheFile
power = something
power123 = 1
power 123 = 1
power =something
power = something