Appending specified property of a specified header within a ini file

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








up vote
1
down vote

favorite












I have a ini file containing Headers with respective property fields to it. For a given Header2 and a property2 how do I append AppendedValue to the property2 by either using sed or awk?



There may be N number of Headers and order of Headers need not be 1, 2 or 3.



Input File1 :



[Header1]

property1 = containsSomeValue
property2 = containsSomeValue
property3 = containsSomeValue

[Header2]

property1 = containsSomeValue
property2 = containsSomeValue
property3 = containsSomeValue


[Header3]

property1 = containsSomeValue
property2 = containsSomeValue
property3 = containsSomeValue


Output File1:



[Header1]

property1 = containsSomeValue
property2 = containsSomeValue
property3 = containsSomeValue

[Header2]

property1 = containsSomeValue
property2 = containsSomeValue AppendedValue
property3 = containsSomeValue


[Header3]

property1 = containsSomeValue
property2 = containsSomeValue
property3 = containsSomeValue






share|improve this question


























    up vote
    1
    down vote

    favorite












    I have a ini file containing Headers with respective property fields to it. For a given Header2 and a property2 how do I append AppendedValue to the property2 by either using sed or awk?



    There may be N number of Headers and order of Headers need not be 1, 2 or 3.



    Input File1 :



    [Header1]

    property1 = containsSomeValue
    property2 = containsSomeValue
    property3 = containsSomeValue

    [Header2]

    property1 = containsSomeValue
    property2 = containsSomeValue
    property3 = containsSomeValue


    [Header3]

    property1 = containsSomeValue
    property2 = containsSomeValue
    property3 = containsSomeValue


    Output File1:



    [Header1]

    property1 = containsSomeValue
    property2 = containsSomeValue
    property3 = containsSomeValue

    [Header2]

    property1 = containsSomeValue
    property2 = containsSomeValue AppendedValue
    property3 = containsSomeValue


    [Header3]

    property1 = containsSomeValue
    property2 = containsSomeValue
    property3 = containsSomeValue






    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a ini file containing Headers with respective property fields to it. For a given Header2 and a property2 how do I append AppendedValue to the property2 by either using sed or awk?



      There may be N number of Headers and order of Headers need not be 1, 2 or 3.



      Input File1 :



      [Header1]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue

      [Header2]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue


      [Header3]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue


      Output File1:



      [Header1]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue

      [Header2]

      property1 = containsSomeValue
      property2 = containsSomeValue AppendedValue
      property3 = containsSomeValue


      [Header3]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue






      share|improve this question














      I have a ini file containing Headers with respective property fields to it. For a given Header2 and a property2 how do I append AppendedValue to the property2 by either using sed or awk?



      There may be N number of Headers and order of Headers need not be 1, 2 or 3.



      Input File1 :



      [Header1]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue

      [Header2]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue


      [Header3]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue


      Output File1:



      [Header1]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue

      [Header2]

      property1 = containsSomeValue
      property2 = containsSomeValue AppendedValue
      property3 = containsSomeValue


      [Header3]

      property1 = containsSomeValue
      property2 = containsSomeValue
      property3 = containsSomeValue








      share|improve this question













      share|improve this question




      share|improve this question








      edited May 24 at 14:13









      αғsнιη

      22.9k2191150




      22.9k2191150










      asked May 24 at 7:04









      DazzlerJay

      464




      464




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Using sed:



          sed "/[Header2]/,/[//^property2/ s/$/ AppendedValue/" infile


          This will look for the lines between [Header2] and [ (which would be the start character of next unknown Header), then append the AppendedValue string to the end of a line if started with property2; the sed-script part only applies for the block matched within given patterns range, and other lines out of this range will be printed with no changes which is sed's default action.



          You can use above in this way too:



          sed "/[Header2]/,/[/s/^property2.*/& AppendedValue/" infile


          If you want to be more specific:



          sed "/^[Header2]/,/^property2//^property2/ s/$/ AppendedValue/" infile





          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            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',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1039689%2fappending-specified-property-of-a-specified-header-within-a-ini-file%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Using sed:



            sed "/[Header2]/,/[//^property2/ s/$/ AppendedValue/" infile


            This will look for the lines between [Header2] and [ (which would be the start character of next unknown Header), then append the AppendedValue string to the end of a line if started with property2; the sed-script part only applies for the block matched within given patterns range, and other lines out of this range will be printed with no changes which is sed's default action.



            You can use above in this way too:



            sed "/[Header2]/,/[/s/^property2.*/& AppendedValue/" infile


            If you want to be more specific:



            sed "/^[Header2]/,/^property2//^property2/ s/$/ AppendedValue/" infile





            share|improve this answer


























              up vote
              1
              down vote



              accepted










              Using sed:



              sed "/[Header2]/,/[//^property2/ s/$/ AppendedValue/" infile


              This will look for the lines between [Header2] and [ (which would be the start character of next unknown Header), then append the AppendedValue string to the end of a line if started with property2; the sed-script part only applies for the block matched within given patterns range, and other lines out of this range will be printed with no changes which is sed's default action.



              You can use above in this way too:



              sed "/[Header2]/,/[/s/^property2.*/& AppendedValue/" infile


              If you want to be more specific:



              sed "/^[Header2]/,/^property2//^property2/ s/$/ AppendedValue/" infile





              share|improve this answer
























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                Using sed:



                sed "/[Header2]/,/[//^property2/ s/$/ AppendedValue/" infile


                This will look for the lines between [Header2] and [ (which would be the start character of next unknown Header), then append the AppendedValue string to the end of a line if started with property2; the sed-script part only applies for the block matched within given patterns range, and other lines out of this range will be printed with no changes which is sed's default action.



                You can use above in this way too:



                sed "/[Header2]/,/[/s/^property2.*/& AppendedValue/" infile


                If you want to be more specific:



                sed "/^[Header2]/,/^property2//^property2/ s/$/ AppendedValue/" infile





                share|improve this answer














                Using sed:



                sed "/[Header2]/,/[//^property2/ s/$/ AppendedValue/" infile


                This will look for the lines between [Header2] and [ (which would be the start character of next unknown Header), then append the AppendedValue string to the end of a line if started with property2; the sed-script part only applies for the block matched within given patterns range, and other lines out of this range will be printed with no changes which is sed's default action.



                You can use above in this way too:



                sed "/[Header2]/,/[/s/^property2.*/& AppendedValue/" infile


                If you want to be more specific:



                sed "/^[Header2]/,/^property2//^property2/ s/$/ AppendedValue/" infile






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 31 at 18:17

























                answered May 24 at 7:24









                αғsнιη

                22.9k2191150




                22.9k2191150






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1039689%2fappending-specified-property-of-a-specified-header-within-a-ini-file%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    pylint3 and pip3 broken

                    Missing snmpget and snmpwalk

                    How to enroll fingerprints to Ubuntu 17.10 with VFS491