I'm trying to automate editing of a configuration file (custom.conf for GDM). I need to find every line between a line that starts with "[daemon]" and the next line that starts with "[". When I find "[daemon]", I want to preserve that line, but then delete all the lines in that configuration section and then insert several new lines of text between the first match ("[daemon]") and the second match ("]").
I suspect that I can do this with sed or at least awk, but I'm not quite sure where to start Can anyone suggest which tool might be better suited to this task and provide some code that accomplishes what I'm talking about?
# Some comments
# S'more comments
[daemon]
TimedLoginEnable=true
TimedLoginDelay=10
TimedLogin=user1
# and maybe some other, unpredictable lines that I don't need or want
[security]
[xdmcp]
[gui]
...
But I feel like the awk script should be more concise, and I also suspect that this can be done in sed, but I don't even know where to start on that one.