How do I use sed to edit the file /etc/heat/heat.conf?

I want to add the new lines under the default section

rabbit_host =controller
rabbit_password =RABBIT_PASS
  • 2
    Research and Try yourself before asking
    – TPS
    Oct 7, 2014 at 10:28
  • 2
    Is this a task you got at school?
    – gena2x
    Oct 7, 2014 at 10:49
  • what exactly do you want to change and why? what is "heat"?
    – rubo77
    Oct 8, 2014 at 16:26

4 Answers 4


You can use a /regexp/ address to find the line containing [DEFAULT], and then an append (a) command to add lines under it. Pass -i to sed to have it modify the file in-place (you might want to run without it first to make sure it's doing the right thing; it will output what the changed file will look like without actually changing it):

# sed -i '/^\[DEFAULT\]$/a rabbit_host =controller\nrabbit_password =RABBIT_PASS' /etc/heat/heat.conf

if you have a file /tmp/a with the contnet

hello my friend

You can use sed to replace strings:

sed -i 's/hello/hi/g' /tmp/a

this will result in:

hi my friend

see: man sed

Also you can add lines without sed to a file by using >>:

echo "I like you">>/tmp/a
  • But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing
    – SuperKrish
    Nov 7, 2016 at 14:25
  • Yes, like i said ;-)
    – rubo77
    Nov 7, 2016 at 14:32

I am sure the requester has found a solution by now but just in case.

This request is ideal for application crudini it is available for all the major linux dustibutions for example the following will add a line to DEFAULT section of /etc/heat/heat.conf

crudini --set /etc/heat/heat.conf DEFAULT mysetting true

The section:

rabbit_host =controller
rabbit_password =RABBIT_PASS
mysetting = true

will update if entry already in conf file.


Old school ed approach

ed -s test <<EOF
rabbit_host =controller
rabbit_password =RABBIT_PASS

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .