Reputation: 199
Im new to sed and found some instructiones to that kind of probmen, but none of them worked for me.
I have a file called var.tf with that entry:
variable "nb_instances" {
description = "Specify the number of vm instances"
default = "3"
}
and want to replace the "3" with "4".
I tried to create that bash skript:
#!/usr/bin/env bash
sed 's/variable \"nb_instances\" {
description = \"Specify the number of vm instances\"
default = \"3\"
}/variable \"nb_instances\" {
description = \"Specify the number of vm instances\"
default = \"4\"
}/g' var.tf
but it doesn´t work and gives an error:
sed: 1: "s/variable \"nb_instanc ...": unterminated substitute pattern
Can anyone help me with that? I also tried to include \n for the new lines.
Upvotes: 0
Views: 56
Reputation: 58568
This might work for you (GNU sed):
sed '/^variable "nb_instances" {/{:a;n;s/"3"/"4"/;Ta}' file
Focus on the first line beginning variable "nb_instances" {
then continue reading/printing lines until the string "3"
is replaced by "4"
.
Upvotes: 1