How do I change a portion of a line after a regexp?
I have a file where I need to modify the line (on the fly) with name = in it but only the one that comes after line with cluster { in it. The file is like this:
cluster {
name = "Some _ Name"
owner = "Cavendish Laboratory"
.....
.....
}
module {
name = "core_metrics"
}
service {
name = "ssh_check"
}
......
......
I can perform this two task separately, like:
sed -n '/cluster\ {/{n;p;}' # next line after cluster
sed -ic "/name\ =\ /{s:OLD:NEW:g}" # replace OLD with NEW on the fly
But how do I combine that two to get the end result like: ?
cluster {
name = "Worker Nodes"
owner = "Cavendish Laboratory"
.....
.....
}
How do I do that? Cheers!
This might work for you:
cluster {and}./cluster {/,/}/newforolds/name = "'"$old"'"/name = "'"$new"'"/