There is a similar question: sed search a range and print first set , but for the life of me, I can't understand how to adapt it to my case.
If I have a config file defined approximately like this:
define global {
alias=main
icon_size=20
object_id=0
map_image=net_map_only.jpg
grid_show=0
}
define line {
x=6c4e2f%+10,5dd361%+10
y=6c4e2f%+10,5dd361%+10
z=90
object_id=2d6bec
view_type=line
line_type=11
line_width=1
line_color=#000000
}
#define line {
#x=266424%+10,604bc6%+10
#y=266424%+10,604bc6%+10
#z=90
#object_id=5b6082
#view_type=line
#line_type=11
#line_width=1
#line_color=#000000
#}
define host {
host_name=INTERNET
x=519
y=307
z=98
object_id=6c4e2f
iconset=std_medium
icon_size=20
label_show=1
label_background=#ffffff
label_border=transparent
label_maxlen=14
}
define host {
host_name=INTERNET
x=519
y=307
z=98
object_id=6c4e2f
iconset=std_medium
icon_size=20
label_show=1
label_background=#ffffff
label_border=transparent
label_maxlen=14
}
There are multiple host entries as you can see above and a lot of other entries (define line, define global, etc). Entry is defined by starting with regex "^define host"
and up to next "}"
.
For debugging purposes I want to selectively comment or delete the first host entry only. As I will iterate through each other host entry and check for errors, I would like to do it from command line.
My initial thought was sed, with:
sed -i '/^define host/,/}/s/^/#/' config.txt
which perfectly comments all host config lines.
However, I can't seem to get it, how to adapt it so that it only does this for the first matching config entry only. Is it even possible?