Edit a file in /etc using shell scripting?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















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



I want to add the new lines under the default section



[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS









share|improve this question



















  • 2





    Research and Try yourself before asking

    – Tejas
    Oct 7 '14 at 10:28






  • 2





    Is this a task you got at school?

    – gena2x
    Oct 7 '14 at 10:49











  • what exactly do you want to change and why? what is "heat"?

    – rubo77
    Oct 8 '14 at 16:26















2















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



I want to add the new lines under the default section



[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS









share|improve this question



















  • 2





    Research and Try yourself before asking

    – Tejas
    Oct 7 '14 at 10:28






  • 2





    Is this a task you got at school?

    – gena2x
    Oct 7 '14 at 10:49











  • what exactly do you want to change and why? what is "heat"?

    – rubo77
    Oct 8 '14 at 16:26













2












2








2


1






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



I want to add the new lines under the default section



[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS









share|improve this question
















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



I want to add the new lines under the default section



[DEFAULT]
rabbit_host =controller
rabbit_password =RABBIT_PASS






shell-script sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 8 '14 at 18:58









Michael Mrozek

61k29189210




61k29189210










asked Oct 7 '14 at 10:24









bpamzbpamz

26113




26113







  • 2





    Research and Try yourself before asking

    – Tejas
    Oct 7 '14 at 10:28






  • 2





    Is this a task you got at school?

    – gena2x
    Oct 7 '14 at 10:49











  • what exactly do you want to change and why? what is "heat"?

    – rubo77
    Oct 8 '14 at 16:26












  • 2





    Research and Try yourself before asking

    – Tejas
    Oct 7 '14 at 10:28






  • 2





    Is this a task you got at school?

    – gena2x
    Oct 7 '14 at 10:49











  • what exactly do you want to change and why? what is "heat"?

    – rubo77
    Oct 8 '14 at 16:26







2




2





Research and Try yourself before asking

– Tejas
Oct 7 '14 at 10:28





Research and Try yourself before asking

– Tejas
Oct 7 '14 at 10:28




2




2





Is this a task you got at school?

– gena2x
Oct 7 '14 at 10:49





Is this a task you got at school?

– gena2x
Oct 7 '14 at 10:49













what exactly do you want to change and why? what is "heat"?

– rubo77
Oct 8 '14 at 16:26





what exactly do you want to change and why? what is "heat"?

– rubo77
Oct 8 '14 at 16:26










4 Answers
4






active

oldest

votes


















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 =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf





share|improve this answer
































    2














    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





    share|improve this answer























    • But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

      – SuperKrish
      Nov 7 '16 at 14:25











    • Yes, like i said ;-)

      – rubo77
      Nov 7 '16 at 14:32


















    0














    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:



    [DEFAULT]
    rabbit_host =controller
    rabbit_password =RABBIT_PASS
    mysetting = true


    will update if entry already in conf file.






    share|improve this answer
































      0














      Old school ed approach



      ed -s test <<EOF
      /^[DEFAULT]$/
      a
      rabbit_host =controller
      rabbit_password =RABBIT_PASS
      .
      w
      q
      EOF





      share|improve this answer






















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f159779%2fedit-a-file-in-etc-using-shell-scripting%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        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 =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf





        share|improve this answer





























          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 =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf





          share|improve this answer



























            4












            4








            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 =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf





            share|improve this answer















            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 =controllernrabbit_password =RABBIT_PASS' /etc/heat/heat.conf






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 8 '14 at 21:53

























            answered Oct 8 '14 at 19:00









            Michael MrozekMichael Mrozek

            61k29189210




            61k29189210























                2














                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





                share|improve this answer























                • But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

                  – SuperKrish
                  Nov 7 '16 at 14:25











                • Yes, like i said ;-)

                  – rubo77
                  Nov 7 '16 at 14:32















                2














                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





                share|improve this answer























                • But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

                  – SuperKrish
                  Nov 7 '16 at 14:25











                • Yes, like i said ;-)

                  – rubo77
                  Nov 7 '16 at 14:32













                2












                2








                2







                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





                share|improve this answer













                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






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 8 '14 at 16:23









                rubo77rubo77

                7,5772572133




                7,5772572133












                • But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

                  – SuperKrish
                  Nov 7 '16 at 14:25











                • Yes, like i said ;-)

                  – rubo77
                  Nov 7 '16 at 14:32

















                • But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

                  – SuperKrish
                  Nov 7 '16 at 14:25











                • Yes, like i said ;-)

                  – rubo77
                  Nov 7 '16 at 14:32
















                But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

                – SuperKrish
                Nov 7 '16 at 14:25





                But echo "I like you">>/tmp/a. It will not replace anything , It just append new thing

                – SuperKrish
                Nov 7 '16 at 14:25













                Yes, like i said ;-)

                – rubo77
                Nov 7 '16 at 14:32





                Yes, like i said ;-)

                – rubo77
                Nov 7 '16 at 14:32











                0














                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:



                [DEFAULT]
                rabbit_host =controller
                rabbit_password =RABBIT_PASS
                mysetting = true


                will update if entry already in conf file.






                share|improve this answer





























                  0














                  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:



                  [DEFAULT]
                  rabbit_host =controller
                  rabbit_password =RABBIT_PASS
                  mysetting = true


                  will update if entry already in conf file.






                  share|improve this answer



























                    0












                    0








                    0







                    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:



                    [DEFAULT]
                    rabbit_host =controller
                    rabbit_password =RABBIT_PASS
                    mysetting = true


                    will update if entry already in conf file.






                    share|improve this answer















                    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:



                    [DEFAULT]
                    rabbit_host =controller
                    rabbit_password =RABBIT_PASS
                    mysetting = true


                    will update if entry already in conf file.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 10 at 19:52









                    Marco

                    774616




                    774616










                    answered Jan 10 at 12:44









                    IT Support GUYIT Support GUY

                    1




                    1





















                        0














                        Old school ed approach



                        ed -s test <<EOF
                        /^[DEFAULT]$/
                        a
                        rabbit_host =controller
                        rabbit_password =RABBIT_PASS
                        .
                        w
                        q
                        EOF





                        share|improve this answer



























                          0














                          Old school ed approach



                          ed -s test <<EOF
                          /^[DEFAULT]$/
                          a
                          rabbit_host =controller
                          rabbit_password =RABBIT_PASS
                          .
                          w
                          q
                          EOF





                          share|improve this answer

























                            0












                            0








                            0







                            Old school ed approach



                            ed -s test <<EOF
                            /^[DEFAULT]$/
                            a
                            rabbit_host =controller
                            rabbit_password =RABBIT_PASS
                            .
                            w
                            q
                            EOF





                            share|improve this answer













                            Old school ed approach



                            ed -s test <<EOF
                            /^[DEFAULT]$/
                            a
                            rabbit_host =controller
                            rabbit_password =RABBIT_PASS
                            .
                            w
                            q
                            EOF






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 10 at 20:00









                            stevesteve

                            14k22452




                            14k22452



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f159779%2fedit-a-file-in-etc-using-shell-scripting%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown






                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay