I have the below lines in a file:
SUT_INST_PIT=true
SUT_INST_TICS=true
SUT_INST_EXAMPLES=false
SUT_INST_PING=false
How can i create a sed line to match pattern SUT_INST_EXAMPLES
& SUT_INST_PING
and set false
to true
?
I can't simply replace false
with true
because I don't want to change SUT_INST_PIT
& SUT_INST_TICS
even if they are false!!!
I have at the moment two sed
commands that are working, but i would like one line only!
sed -i "s/SUT_INST_EXAMPLES=false/SUT_INST_EXAMPLES=true/g" <file>
sed -i "s/SUT_INST_PING=false/SUT_INST_PING=true/g" <file>
One more thing the sed
line should be able to be parametrized to set false
->true
or true
->false
, but only for SUT_INST_EXAMPLES
& SUT_INST_PING
.
Solution (according to @RomanPerekhrest) and how to use it in send (expect script):
send "sed -i 's\/^\\(SUT_INST_EXAMPLES\\|SUT_INST_PING\\)=false\/\\1=true\/' file\r"
Best Answer
sed approach:
file
contents:\(SUT_INST_EXAMPLES\|SUT_INST_PING\)
- alternation group, matches eitherSUT_INST_EXAMPLES
ORSUT_INST_PING
at the start of the stringAlternative gawk(GNU awk) approach: