Replacing .* in vi

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











up vote
2
down vote

favorite












I need to replace all occurrences of "period asterisk" as it is shown here:



blah blah .*:.*:.* blah blah


with:



[0-9][0-9]:[0-9][0-9]:[0-9][0-9]


so that the end result looks like this:



blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah


I tried different variations of the following but it didn't work:



%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g









share|improve this question



























    up vote
    2
    down vote

    favorite












    I need to replace all occurrences of "period asterisk" as it is shown here:



    blah blah .*:.*:.* blah blah


    with:



    [0-9][0-9]:[0-9][0-9]:[0-9][0-9]


    so that the end result looks like this:



    blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah


    I tried different variations of the following but it didn't work:



    %s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g









    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I need to replace all occurrences of "period asterisk" as it is shown here:



      blah blah .*:.*:.* blah blah


      with:



      [0-9][0-9]:[0-9][0-9]:[0-9][0-9]


      so that the end result looks like this:



      blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah


      I tried different variations of the following but it didn't work:



      %s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g









      share|improve this question















      I need to replace all occurrences of "period asterisk" as it is shown here:



      blah blah .*:.*:.* blah blah


      with:



      [0-9][0-9]:[0-9][0-9]:[0-9][0-9]


      so that the end result looks like this:



      blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah


      I tried different variations of the following but it didn't work:



      %s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g






      sed regular-expression vi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 19 '17 at 10:19









      Kusalananda

      106k14209327




      106k14209327










      asked Sep 24 '17 at 23:20









      swenson

      112




      112




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote













          For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g



          For sed: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'.




          • % means apply the substitution on all lines; is not needed in sed where by default the command is applied to all lines.


          • . is a period; a bare . means any character.


          • * is an asterisk; a bare * means 0 or more of the preceding atom.





          share|improve this answer



























            up vote
            2
            down vote













            You gave an example of a line with “period asterisk” repeated three times,
            separated by colons. 
            If your data will always look like that, you might as well stick
            with AlexP’s answer. 
            But your question says
            that you need to replace all occurrences of “period asterisk”. 
            If that statement of the problem is accurate, you should use



            :%s/.*/[0-9][0-9]/g


            which will find and replace “period asterisk”
            even when it doesn’t appear in groups of three.






            share|improve this answer



























              up vote
              0
              down vote













              Using the nomagic modifier for the pattern in Vim:



              :%s/M.*/[0-9][0-9]/g


              The M will remove the specialness of both . and * in the pattern.



              See :help magic in Vim.






              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%2f394213%2freplacing-in-vi%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                2
                down vote













                For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g



                For sed: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'.




                • % means apply the substitution on all lines; is not needed in sed where by default the command is applied to all lines.


                • . is a period; a bare . means any character.


                • * is an asterisk; a bare * means 0 or more of the preceding atom.





                share|improve this answer
























                  up vote
                  2
                  down vote













                  For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g



                  For sed: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'.




                  • % means apply the substitution on all lines; is not needed in sed where by default the command is applied to all lines.


                  • . is a period; a bare . means any character.


                  • * is an asterisk; a bare * means 0 or more of the preceding atom.





                  share|improve this answer






















                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g



                    For sed: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'.




                    • % means apply the substitution on all lines; is not needed in sed where by default the command is applied to all lines.


                    • . is a period; a bare . means any character.


                    • * is an asterisk; a bare * means 0 or more of the preceding atom.





                    share|improve this answer












                    For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g



                    For sed: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'.




                    • % means apply the substitution on all lines; is not needed in sed where by default the command is applied to all lines.


                    • . is a period; a bare . means any character.


                    • * is an asterisk; a bare * means 0 or more of the preceding atom.






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 24 '17 at 23:38









                    AlexP

                    6,656924




                    6,656924






















                        up vote
                        2
                        down vote













                        You gave an example of a line with “period asterisk” repeated three times,
                        separated by colons. 
                        If your data will always look like that, you might as well stick
                        with AlexP’s answer. 
                        But your question says
                        that you need to replace all occurrences of “period asterisk”. 
                        If that statement of the problem is accurate, you should use



                        :%s/.*/[0-9][0-9]/g


                        which will find and replace “period asterisk”
                        even when it doesn’t appear in groups of three.






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          You gave an example of a line with “period asterisk” repeated three times,
                          separated by colons. 
                          If your data will always look like that, you might as well stick
                          with AlexP’s answer. 
                          But your question says
                          that you need to replace all occurrences of “period asterisk”. 
                          If that statement of the problem is accurate, you should use



                          :%s/.*/[0-9][0-9]/g


                          which will find and replace “period asterisk”
                          even when it doesn’t appear in groups of three.






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            You gave an example of a line with “period asterisk” repeated three times,
                            separated by colons. 
                            If your data will always look like that, you might as well stick
                            with AlexP’s answer. 
                            But your question says
                            that you need to replace all occurrences of “period asterisk”. 
                            If that statement of the problem is accurate, you should use



                            :%s/.*/[0-9][0-9]/g


                            which will find and replace “period asterisk”
                            even when it doesn’t appear in groups of three.






                            share|improve this answer












                            You gave an example of a line with “period asterisk” repeated three times,
                            separated by colons. 
                            If your data will always look like that, you might as well stick
                            with AlexP’s answer. 
                            But your question says
                            that you need to replace all occurrences of “period asterisk”. 
                            If that statement of the problem is accurate, you should use



                            :%s/.*/[0-9][0-9]/g


                            which will find and replace “period asterisk”
                            even when it doesn’t appear in groups of three.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 25 '17 at 5:01









                            Scott

                            6,30742448




                            6,30742448




















                                up vote
                                0
                                down vote













                                Using the nomagic modifier for the pattern in Vim:



                                :%s/M.*/[0-9][0-9]/g


                                The M will remove the specialness of both . and * in the pattern.



                                See :help magic in Vim.






                                share|improve this answer
























                                  up vote
                                  0
                                  down vote













                                  Using the nomagic modifier for the pattern in Vim:



                                  :%s/M.*/[0-9][0-9]/g


                                  The M will remove the specialness of both . and * in the pattern.



                                  See :help magic in Vim.






                                  share|improve this answer






















                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    Using the nomagic modifier for the pattern in Vim:



                                    :%s/M.*/[0-9][0-9]/g


                                    The M will remove the specialness of both . and * in the pattern.



                                    See :help magic in Vim.






                                    share|improve this answer












                                    Using the nomagic modifier for the pattern in Vim:



                                    :%s/M.*/[0-9][0-9]/g


                                    The M will remove the specialness of both . and * in the pattern.



                                    See :help magic in Vim.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Oct 19 '17 at 10:16









                                    Kusalananda

                                    106k14209327




                                    106k14209327



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394213%2freplacing-in-vi%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Popular posts from this blog

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

                                        Displaying single band from multi-band raster using QGIS

                                        How many registers does an x86_64 CPU actually have?