# Get a range of lines from a file and replace a line in that range using awk or sed or both

I would like to replace a line in a section of the smb.conf file using either awk or sed or both if need be. Here's the section in the file...

[CMI] oplocks = no wide links = no writeable = yes delete readonly = yes path = /LOCALSITE/CMI comment = CMI Data write list = @cbishare valid users = @cbishare create mode = 775 directory mode = 775

I would like to use this code for later reuse with a variable to run on different sections of the smb.conf file. So just finding "write list" in each section will not work.

I am able to parse the file and get the section using this code...

awk '/$\CMI\>$/,/^$/' /etc/samba/smb.conf  or with sed... sed -n '/$\CMI\>$/,/^$/{p}' /etc/samba/smb.conf


I now need to replace in the file a specific line in that range like 'write list'. I am a novice with sed or awk and I haven't found any info on how to accomplish the last part.

I thought maybe i could get the NR of the line and then use sed to rewrite it.

Any thoughts on how to do this or links to a solution would be greatly appreciated.