regex - Multiline pattern after pattern match using sed -
i have config file consists of multiple sections , lots of them contain property same name, let host
. need replace host
property of 1 particular section only. here's file:
section1 { ... setting1 = "true" ... host = "localhost" ... } section2 { ... host = "whatever" ... }
i want replace host
value of section2
else. note there may number of lines in between, marked ...
sed -i.bak '/^section2 {/,/^}/s/host .*/host = "newvalue"/' file
this search between section2 {
, next }
, changing host =
occurences. gnu sed syntax, should use eg sed -i '' ...
on osx.
Comments
Post a Comment