I have a simple config file that looks a bit like this:
[sectionA]
url = value1
username = value2
password = value3
[sectionC]
url = value1
username = value2
password = value3
[sectionB]
url = value1
username = value2
password = value3
And I want to replace the username for SectionB to be valueX
without touching SectionA's or SectionC's username.
I've tried some variations on sed
, but as far as I've managed to fathom it seems to operate on individual lines.
How do I do the equivalent of
[SectionB]
)username = value2
)sed
:sed '/sectionB/,/\[/s/username.*/username = valueX/' input
awk
:awk -vRS='' -vFS='\n' -vOFS='\n' '
$1~/sectionB/{
sub(/=.*$/, "= valueX", $3)
}
{
printf "%s\n\n", $0
}' input