Issue
I have a file called tst.txt that contains text:
exec(compile(open(bla bla bla'))
DATE = "05JUN20"
Only capture the below line
params = {'System_Date': getparamDate(DATE), 'Param': '2'}
This Line should be available
''End
'Short description:
'bla bla bli, bla bla bla
First line with }
Normal Line without bracket
Another bracket}&
Then normal text
blabla
blublu
tatati
I want to capture and change only the line:
params = {'System_Date': getparamDate(DATE), 'Param': '2'}
in my file.
I've fond a sed command that allow to substitute what is between patterns. /c
sed -i '/params = {/,/}/c params = MyNewParam' tst.txt
where I intend to substitute only what is between:
params = {
and
} from the same line.
unfortunately, my regex will replace until First line with }
exec(compile(open(bla bla bla'))
DATE = "05JUN20"
Only capture the below line
params = MyNewParam
Normal Line without bracket
Another bracket}&
Then normal text
blabla
blublu
tatati
I5TaxActivationDate
which is not what I expect.
I've seen that with
,/}/q
it's possible to stop at the first occurrence, I cannot find the right syntax.
Can anyone help please?
Thanks in advance
Solution
This might work for you (GNU sed):
sed -e '/params = {.*}/c CHANGE ONE' -e '/params = {/,/}/c CHANGE MULTIPLE' file
If a line contains the whole pattern then only change that line, otherwise try to fit the pattern over multiple lines.
Answered By - potong Answer Checked By - Candace Johnson (WPSolving Volunteer)