sed + mark line in case of marched word

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-1
down vote

favorite












we want to mark with "#" the matched line by sed or perl line liner



for example



we want to mark all lines in file that include the DatePattern word



log4j.appender.DRFA.DatePattern=.yyyy-MM-dd


expected output



#log4j.appender.DRFA.DatePattern


note - in case line already marked then it will not add another "#" before the line







share|improve this question



























    up vote
    -1
    down vote

    favorite












    we want to mark with "#" the matched line by sed or perl line liner



    for example



    we want to mark all lines in file that include the DatePattern word



    log4j.appender.DRFA.DatePattern=.yyyy-MM-dd


    expected output



    #log4j.appender.DRFA.DatePattern


    note - in case line already marked then it will not add another "#" before the line







    share|improve this question























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      we want to mark with "#" the matched line by sed or perl line liner



      for example



      we want to mark all lines in file that include the DatePattern word



      log4j.appender.DRFA.DatePattern=.yyyy-MM-dd


      expected output



      #log4j.appender.DRFA.DatePattern


      note - in case line already marked then it will not add another "#" before the line







      share|improve this question













      we want to mark with "#" the matched line by sed or perl line liner



      for example



      we want to mark all lines in file that include the DatePattern word



      log4j.appender.DRFA.DatePattern=.yyyy-MM-dd


      expected output



      #log4j.appender.DRFA.DatePattern


      note - in case line already marked then it will not add another "#" before the line









      share|improve this question












      share|improve this question




      share|improve this question








      edited yesterday









      Jeff Schaller

      30.7k846104




      30.7k846104









      asked yesterday









      yael

      1,786940




      1,786940




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Prepending # to the line and also removing the = and whatever comes after it:



          sed 's/^([^#].*DatePattern)=.*/#1/' file


          Alternatively, not removing the =:



          sed 's/^[^#].*DatePattern/#&/' file





          share|improve this answer























          • do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
            – yael
            yesterday

















          up vote
          1
          down vote













          In case you don't want to remove the trailing date pattern (your spec is not quite clear), try



          sed '/^[^#].*DatePattern/ s/^/#/' file





          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f460645%2fsed-mark-line-in-case-of-marched-word%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Prepending # to the line and also removing the = and whatever comes after it:



            sed 's/^([^#].*DatePattern)=.*/#1/' file


            Alternatively, not removing the =:



            sed 's/^[^#].*DatePattern/#&/' file





            share|improve this answer























            • do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
              – yael
              yesterday














            up vote
            1
            down vote



            accepted










            Prepending # to the line and also removing the = and whatever comes after it:



            sed 's/^([^#].*DatePattern)=.*/#1/' file


            Alternatively, not removing the =:



            sed 's/^[^#].*DatePattern/#&/' file





            share|improve this answer























            • do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
              – yael
              yesterday












            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Prepending # to the line and also removing the = and whatever comes after it:



            sed 's/^([^#].*DatePattern)=.*/#1/' file


            Alternatively, not removing the =:



            sed 's/^[^#].*DatePattern/#&/' file





            share|improve this answer















            Prepending # to the line and also removing the = and whatever comes after it:



            sed 's/^([^#].*DatePattern)=.*/#1/' file


            Alternatively, not removing the =:



            sed 's/^[^#].*DatePattern/#&/' file






            share|improve this answer















            share|improve this answer



            share|improve this answer








            edited yesterday


























            answered yesterday









            Kusalananda

            100k13199311




            100k13199311











            • do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
              – yael
              yesterday
















            • do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
              – yael
              yesterday















            do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
            – yael
            yesterday




            do you have another suggestion from my question on - unix.stackexchange.com/questions/460642/…
            – yael
            yesterday












            up vote
            1
            down vote













            In case you don't want to remove the trailing date pattern (your spec is not quite clear), try



            sed '/^[^#].*DatePattern/ s/^/#/' file





            share|improve this answer

























              up vote
              1
              down vote













              In case you don't want to remove the trailing date pattern (your spec is not quite clear), try



              sed '/^[^#].*DatePattern/ s/^/#/' file





              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                In case you don't want to remove the trailing date pattern (your spec is not quite clear), try



                sed '/^[^#].*DatePattern/ s/^/#/' file





                share|improve this answer













                In case you don't want to remove the trailing date pattern (your spec is not quite clear), try



                sed '/^[^#].*DatePattern/ s/^/#/' file






                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered yesterday









                RudiC

                612




                612






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460645%2fsed-mark-line-in-case-of-marched-word%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)