Sometime you cant use sed :(
with open('file.txt', 'r') as file :
filedata = file.read()
filedata = filedata.replace('ram', 'abcd')
with open('file.txt', 'w') as file:
file.write(filedata)
Use
sed '/#start/,/#end/replace_command'
For example, if the file is called myconfig, and you want to replace "allow" with "deny" in that section, you could say
sed '/#start/,/#end/s/allow/deny/' myconfig
example
sed -i -r "//,/<\/elasticConfig>/s,.+,false," file.xml