text file search yyyy/mm/dd and replace with yyyy-mm-dd

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











up vote
0
down vote

favorite












I have a file with many tags in the form of yyyy/mm/dd as in the line below and want to replace the / with - to give yyyy-mm-dd at all instances in the one file.
e.g.



from this: <tag k='start_date' v='2011/01/01' />

to this: <tag k='start_date' v='2011-01-01' />



I'm on Mac 10.11.6







share|improve this question





















  • are you able to install xml/html parsers?
    – RomanPerekhrest
    Apr 20 at 6:35














up vote
0
down vote

favorite












I have a file with many tags in the form of yyyy/mm/dd as in the line below and want to replace the / with - to give yyyy-mm-dd at all instances in the one file.
e.g.



from this: <tag k='start_date' v='2011/01/01' />

to this: <tag k='start_date' v='2011-01-01' />



I'm on Mac 10.11.6







share|improve this question





















  • are you able to install xml/html parsers?
    – RomanPerekhrest
    Apr 20 at 6:35












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a file with many tags in the form of yyyy/mm/dd as in the line below and want to replace the / with - to give yyyy-mm-dd at all instances in the one file.
e.g.



from this: <tag k='start_date' v='2011/01/01' />

to this: <tag k='start_date' v='2011-01-01' />



I'm on Mac 10.11.6







share|improve this question













I have a file with many tags in the form of yyyy/mm/dd as in the line below and want to replace the / with - to give yyyy-mm-dd at all instances in the one file.
e.g.



from this: <tag k='start_date' v='2011/01/01' />

to this: <tag k='start_date' v='2011-01-01' />



I'm on Mac 10.11.6









share|improve this question












share|improve this question




share|improve this question








edited Apr 20 at 5:30









αғsнιη

14.8k82462




14.8k82462









asked Apr 20 at 4:41









Nev

1




1











  • are you able to install xml/html parsers?
    – RomanPerekhrest
    Apr 20 at 6:35
















  • are you able to install xml/html parsers?
    – RomanPerekhrest
    Apr 20 at 6:35















are you able to install xml/html parsers?
– RomanPerekhrest
Apr 20 at 6:35




are you able to install xml/html parsers?
– RomanPerekhrest
Apr 20 at 6:35










2 Answers
2






active

oldest

votes

















up vote
2
down vote













You can use sed for that



$ sed -E 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file


Give a try.



To edit the file in place, with macOS or FreeBSD, add a -i '' option. Most of other sed implementations need -i alone for that (-i.back would work for both and save the original with a .back extension). On systems where sed doesn't support in-place editing, you can use perl -pi -e in place of sed -E (which inspired those sed -i).






share|improve this answer






























    up vote
    -1
    down vote













    Sorry, no it did not work.
    The text is unchanged



    But this worked fine ...



    perl -pi -e 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' 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%2f438867%2ftext-file-search-yyyy-mm-dd-and-replace-with-yyyy-mm-dd%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
      2
      down vote













      You can use sed for that



      $ sed -E 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file


      Give a try.



      To edit the file in place, with macOS or FreeBSD, add a -i '' option. Most of other sed implementations need -i alone for that (-i.back would work for both and save the original with a .back extension). On systems where sed doesn't support in-place editing, you can use perl -pi -e in place of sed -E (which inspired those sed -i).






      share|improve this answer



























        up vote
        2
        down vote













        You can use sed for that



        $ sed -E 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file


        Give a try.



        To edit the file in place, with macOS or FreeBSD, add a -i '' option. Most of other sed implementations need -i alone for that (-i.back would work for both and save the original with a .back extension). On systems where sed doesn't support in-place editing, you can use perl -pi -e in place of sed -E (which inspired those sed -i).






        share|improve this answer

























          up vote
          2
          down vote










          up vote
          2
          down vote









          You can use sed for that



          $ sed -E 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file


          Give a try.



          To edit the file in place, with macOS or FreeBSD, add a -i '' option. Most of other sed implementations need -i alone for that (-i.back would work for both and save the original with a .back extension). On systems where sed doesn't support in-place editing, you can use perl -pi -e in place of sed -E (which inspired those sed -i).






          share|improve this answer















          You can use sed for that



          $ sed -E 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file


          Give a try.



          To edit the file in place, with macOS or FreeBSD, add a -i '' option. Most of other sed implementations need -i alone for that (-i.back would work for both and save the original with a .back extension). On systems where sed doesn't support in-place editing, you can use perl -pi -e in place of sed -E (which inspired those sed -i).







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Apr 20 at 13:04









          Stéphane Chazelas

          279k53514846




          279k53514846











          answered Apr 20 at 4:48









          tachomi

          3,39431134




          3,39431134






















              up vote
              -1
              down vote













              Sorry, no it did not work.
              The text is unchanged



              But this worked fine ...



              perl -pi -e 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file





              share|improve this answer



























                up vote
                -1
                down vote













                Sorry, no it did not work.
                The text is unchanged



                But this worked fine ...



                perl -pi -e 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file





                share|improve this answer

























                  up vote
                  -1
                  down vote










                  up vote
                  -1
                  down vote









                  Sorry, no it did not work.
                  The text is unchanged



                  But this worked fine ...



                  perl -pi -e 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file





                  share|improve this answer















                  Sorry, no it did not work.
                  The text is unchanged



                  But this worked fine ...



                  perl -pi -e 's|([0-9]4)/([0-9]2)/([0-9]2)|1-2-3|g' file






                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited Apr 20 at 7:23









                  Romeo Ninov

                  4,35811625




                  4,35811625











                  answered Apr 20 at 5:23









                  nwastra

                  11




                  11






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438867%2ftext-file-search-yyyy-mm-dd-and-replace-with-yyyy-mm-dd%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?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay