Use awk to format date field

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











up vote
-1
down vote

favorite












How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing “Month” with the current month name (three-letter abbreviation) and “Year” with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".







share|improve this question





















  • Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
    – ilkkachu
    Jul 10 at 18:43











  • @ilkkachu No July 2018 is not a constant.
    – fball4life36
    Jul 10 at 18:46










  • you want current month and year to be inserted?
    – SivaPrasath
    Jul 10 at 18:52










  • @sivaPrasath Yes.
    – fball4life36
    Jul 10 at 19:05






  • 1




    Why does it have to be awk?
    – roaima
    Jul 10 at 19:53














up vote
-1
down vote

favorite












How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing “Month” with the current month name (three-letter abbreviation) and “Year” with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".







share|improve this question





















  • Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
    – ilkkachu
    Jul 10 at 18:43











  • @ilkkachu No July 2018 is not a constant.
    – fball4life36
    Jul 10 at 18:46










  • you want current month and year to be inserted?
    – SivaPrasath
    Jul 10 at 18:52










  • @sivaPrasath Yes.
    – fball4life36
    Jul 10 at 19:05






  • 1




    Why does it have to be awk?
    – roaima
    Jul 10 at 19:53












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing “Month” with the current month name (three-letter abbreviation) and “Year” with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".







share|improve this question













How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing “Month” with the current month name (three-letter abbreviation) and “Year” with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".









share|improve this question












share|improve this question




share|improve this question








edited Jul 11 at 4:47









G-Man

11.4k82656




11.4k82656









asked Jul 10 at 18:27









fball4life36

347




347











  • Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
    – ilkkachu
    Jul 10 at 18:43











  • @ilkkachu No July 2018 is not a constant.
    – fball4life36
    Jul 10 at 18:46










  • you want current month and year to be inserted?
    – SivaPrasath
    Jul 10 at 18:52










  • @sivaPrasath Yes.
    – fball4life36
    Jul 10 at 19:05






  • 1




    Why does it have to be awk?
    – roaima
    Jul 10 at 19:53
















  • Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
    – ilkkachu
    Jul 10 at 18:43











  • @ilkkachu No July 2018 is not a constant.
    – fball4life36
    Jul 10 at 18:46










  • you want current month and year to be inserted?
    – SivaPrasath
    Jul 10 at 18:52










  • @sivaPrasath Yes.
    – fball4life36
    Jul 10 at 19:05






  • 1




    Why does it have to be awk?
    – roaima
    Jul 10 at 19:53















Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
– ilkkachu
Jul 10 at 18:43





Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
– ilkkachu
Jul 10 at 18:43













@ilkkachu No July 2018 is not a constant.
– fball4life36
Jul 10 at 18:46




@ilkkachu No July 2018 is not a constant.
– fball4life36
Jul 10 at 18:46












you want current month and year to be inserted?
– SivaPrasath
Jul 10 at 18:52




you want current month and year to be inserted?
– SivaPrasath
Jul 10 at 18:52












@sivaPrasath Yes.
– fball4life36
Jul 10 at 19:05




@sivaPrasath Yes.
– fball4life36
Jul 10 at 19:05




1




1




Why does it have to be awk?
– roaima
Jul 10 at 19:53




Why does it have to be awk?
– roaima
Jul 10 at 19:53










3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










simply,



echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'


If you are keen to have month in upper case:



echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'





share|improve this answer






























    up vote
    1
    down vote













    Not sure how robust you are needing this, but here is a start:



    #!/usr/bin/awk -f
    BEGIN
    FS = "-"


    print $1 "-MONTH-YEAR", $2






    share|improve this answer






























      up vote
      0
      down vote













      If you have GNU Awk (gawk), you can use its built-in systime and strftime



      gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2' 


      Ex.



      $ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
      09 Jul 2018 12:36:10


      If you need the abbreviated month in upper case, try %^b e.g.



      $ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
      09-JUL-2018 12:36:10





      share|improve this answer























      • interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
        – SivaPrasath
        Jul 10 at 21:10







      • 1




        @SivaPrasath done
        – steeldriver
        Jul 10 at 21:16










      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%2f454548%2fuse-awk-to-format-date-field%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
      1
      down vote



      accepted










      simply,



      echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'


      If you are keen to have month in upper case:



      echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'





      share|improve this answer



























        up vote
        1
        down vote



        accepted










        simply,



        echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'


        If you are keen to have month in upper case:



        echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'





        share|improve this answer

























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          simply,



          echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'


          If you are keen to have month in upper case:



          echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'





          share|improve this answer















          simply,



          echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'


          If you are keen to have month in upper case:



          echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jul 10 at 19:27


























          answered Jul 10 at 18:48









          SivaPrasath

          3,68311636




          3,68311636






















              up vote
              1
              down vote













              Not sure how robust you are needing this, but here is a start:



              #!/usr/bin/awk -f
              BEGIN
              FS = "-"


              print $1 "-MONTH-YEAR", $2






              share|improve this answer



























                up vote
                1
                down vote













                Not sure how robust you are needing this, but here is a start:



                #!/usr/bin/awk -f
                BEGIN
                FS = "-"


                print $1 "-MONTH-YEAR", $2






                share|improve this answer

























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Not sure how robust you are needing this, but here is a start:



                  #!/usr/bin/awk -f
                  BEGIN
                  FS = "-"


                  print $1 "-MONTH-YEAR", $2






                  share|improve this answer















                  Not sure how robust you are needing this, but here is a start:



                  #!/usr/bin/awk -f
                  BEGIN
                  FS = "-"


                  print $1 "-MONTH-YEAR", $2







                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited Jul 10 at 20:29


























                  answered Jul 10 at 18:36









                  Steven Penny

                  2,30221535




                  2,30221535




















                      up vote
                      0
                      down vote













                      If you have GNU Awk (gawk), you can use its built-in systime and strftime



                      gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2' 


                      Ex.



                      $ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
                      09 Jul 2018 12:36:10


                      If you need the abbreviated month in upper case, try %^b e.g.



                      $ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
                      09-JUL-2018 12:36:10





                      share|improve this answer























                      • interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
                        – SivaPrasath
                        Jul 10 at 21:10







                      • 1




                        @SivaPrasath done
                        – steeldriver
                        Jul 10 at 21:16














                      up vote
                      0
                      down vote













                      If you have GNU Awk (gawk), you can use its built-in systime and strftime



                      gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2' 


                      Ex.



                      $ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
                      09 Jul 2018 12:36:10


                      If you need the abbreviated month in upper case, try %^b e.g.



                      $ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
                      09-JUL-2018 12:36:10





                      share|improve this answer























                      • interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
                        – SivaPrasath
                        Jul 10 at 21:10







                      • 1




                        @SivaPrasath done
                        – steeldriver
                        Jul 10 at 21:16












                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      If you have GNU Awk (gawk), you can use its built-in systime and strftime



                      gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2' 


                      Ex.



                      $ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
                      09 Jul 2018 12:36:10


                      If you need the abbreviated month in upper case, try %^b e.g.



                      $ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
                      09-JUL-2018 12:36:10





                      share|improve this answer















                      If you have GNU Awk (gawk), you can use its built-in systime and strftime



                      gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2' 


                      Ex.



                      $ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
                      09 Jul 2018 12:36:10


                      If you need the abbreviated month in upper case, try %^b e.g.



                      $ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
                      09-JUL-2018 12:36:10






                      share|improve this answer















                      share|improve this answer



                      share|improve this answer








                      edited Jul 10 at 21:15


























                      answered Jul 10 at 20:50









                      steeldriver

                      30.9k34877




                      30.9k34877











                      • interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
                        – SivaPrasath
                        Jul 10 at 21:10







                      • 1




                        @SivaPrasath done
                        – steeldriver
                        Jul 10 at 21:16
















                      • interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
                        – SivaPrasath
                        Jul 10 at 21:10







                      • 1




                        @SivaPrasath done
                        – steeldriver
                        Jul 10 at 21:16















                      interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
                      – SivaPrasath
                      Jul 10 at 21:10





                      interesting!! can you update the answer with desired format 09-JUL-2018 12:36:10
                      – SivaPrasath
                      Jul 10 at 21:10





                      1




                      1




                      @SivaPrasath done
                      – steeldriver
                      Jul 10 at 21:16




                      @SivaPrasath done
                      – steeldriver
                      Jul 10 at 21:16












                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454548%2fuse-awk-to-format-date-field%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?

                      Christian Cage

                      How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?