[SOLVED] Regex - Modify Parameter in config file
by angel115 from LinuxQuestions.org on (#5PGWQ)
Hi There,
I'd like to modify a parameter in a config file using a regex
Sample config file:
Code:[ServiceXY]
ParamXY=true
Enable=False
[Service123]
ParamXY=true
Enable=False
[Service345]
ParamXY=true
Enable=False
[Service456]
ParamXY=true
Enable=FalseMy goal is to modify the "Enable=False" of the section "Service345" to "Enable=True"
The following work fine in Regex101.com
Match
Code:/(\[Service345\]\r?\n.*(\r?\n([^[\r\n].*)?)*Enable=)False/And use this as substitution
Code:/$1True/
But when I try to use it in command line it doesn't work:
Code:perl -pe 's/(\[Service345\]\r?\n.*(\r?\n([^[\r\n].*)?)*Enable=)False/\1/gm' test.confAny Idea why it doesn't substitute in command line?
Thanks for your help.
I'd like to modify a parameter in a config file using a regex
Sample config file:
Code:[ServiceXY]
ParamXY=true
Enable=False
[Service123]
ParamXY=true
Enable=False
[Service345]
ParamXY=true
Enable=False
[Service456]
ParamXY=true
Enable=FalseMy goal is to modify the "Enable=False" of the section "Service345" to "Enable=True"
The following work fine in Regex101.com
Match
Code:/(\[Service345\]\r?\n.*(\r?\n([^[\r\n].*)?)*Enable=)False/And use this as substitution
Code:/$1True/
But when I try to use it in command line it doesn't work:
Code:perl -pe 's/(\[Service345\]\r?\n.*(\r?\n([^[\r\n].*)?)*Enable=)False/\1/gm' test.confAny Idea why it doesn't substitute in command line?
Thanks for your help.