Edit comma seperated fields

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











up vote
0
down vote

favorite












Input:



1,012018,111
2,1-2018,111
3,10-2018,111


Output:



1,01/2018,111
2,01/2018,111
3,10/2018,111


How can i achieve that which meaning edit of month and year to be mm/yyyy







share|improve this question























    up vote
    0
    down vote

    favorite












    Input:



    1,012018,111
    2,1-2018,111
    3,10-2018,111


    Output:



    1,01/2018,111
    2,01/2018,111
    3,10/2018,111


    How can i achieve that which meaning edit of month and year to be mm/yyyy







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Input:



      1,012018,111
      2,1-2018,111
      3,10-2018,111


      Output:



      1,01/2018,111
      2,01/2018,111
      3,10/2018,111


      How can i achieve that which meaning edit of month and year to be mm/yyyy







      share|improve this question











      Input:



      1,012018,111
      2,1-2018,111
      3,10-2018,111


      Output:



      1,01/2018,111
      2,01/2018,111
      3,10/2018,111


      How can i achieve that which meaning edit of month and year to be mm/yyyy









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 3 at 20:56









      αԋɱҽԃ αмєяιcαη

      396418




      396418




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          With GNU Awk, using patsplit to split the second comma delimited field into subfields of at most two decimal digits:



          $ gawk 'BEGINOFS=FS="," patsplit($2,a,/[0-9][0-9]?/); $2 = sprintf("%02d/%d%d", a[1], a[2], a[3]) 1' file
          1,01/2018,111
          2,01/2018,111
          3,10/2018,111


          If Perl is an option



          perl -F, -lpe '
          $F[1] =~ s(dd?)-?(d+)sprintf "%02d/%d", $1, $2e;
          $_ = join ",", @F
          ' file





          share|improve this answer






























            up vote
            0
            down vote













            sed -e 's/^(.),(.),(.)/2/g' -e 's/([0-9]1,2)([0-9]4)/1-2/g' file*



            s/^(.),(.),(.*)/2/g - splits based on commas and gets 2nd value
            s/([0-9]1,2)([0-9]4)/1-2/g - splits and inserts '-' between year and month






            share|improve this answer






























              up vote
              0
              down vote













              sed -e 's/^(.),([0-9]1,2)([0-9]4),(.)/1,2-3,4/g' test.txt



              • ^(.*), = capture until first ',' and stored in 1

              • ([0-9]1,2) = capture 1 or 2 digit number and store in 2

              • ([0-9]4) = capture 4 didit no and store in 3

              • ,(.*) 4 = capture the rest from ',' and store it in 4

              • And replace accordingly





              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%2f453308%2fedit-comma-seperated-fields%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










                With GNU Awk, using patsplit to split the second comma delimited field into subfields of at most two decimal digits:



                $ gawk 'BEGINOFS=FS="," patsplit($2,a,/[0-9][0-9]?/); $2 = sprintf("%02d/%d%d", a[1], a[2], a[3]) 1' file
                1,01/2018,111
                2,01/2018,111
                3,10/2018,111


                If Perl is an option



                perl -F, -lpe '
                $F[1] =~ s(dd?)-?(d+)sprintf "%02d/%d", $1, $2e;
                $_ = join ",", @F
                ' file





                share|improve this answer



























                  up vote
                  1
                  down vote



                  accepted










                  With GNU Awk, using patsplit to split the second comma delimited field into subfields of at most two decimal digits:



                  $ gawk 'BEGINOFS=FS="," patsplit($2,a,/[0-9][0-9]?/); $2 = sprintf("%02d/%d%d", a[1], a[2], a[3]) 1' file
                  1,01/2018,111
                  2,01/2018,111
                  3,10/2018,111


                  If Perl is an option



                  perl -F, -lpe '
                  $F[1] =~ s(dd?)-?(d+)sprintf "%02d/%d", $1, $2e;
                  $_ = join ",", @F
                  ' file





                  share|improve this answer

























                    up vote
                    1
                    down vote



                    accepted







                    up vote
                    1
                    down vote



                    accepted






                    With GNU Awk, using patsplit to split the second comma delimited field into subfields of at most two decimal digits:



                    $ gawk 'BEGINOFS=FS="," patsplit($2,a,/[0-9][0-9]?/); $2 = sprintf("%02d/%d%d", a[1], a[2], a[3]) 1' file
                    1,01/2018,111
                    2,01/2018,111
                    3,10/2018,111


                    If Perl is an option



                    perl -F, -lpe '
                    $F[1] =~ s(dd?)-?(d+)sprintf "%02d/%d", $1, $2e;
                    $_ = join ",", @F
                    ' file





                    share|improve this answer















                    With GNU Awk, using patsplit to split the second comma delimited field into subfields of at most two decimal digits:



                    $ gawk 'BEGINOFS=FS="," patsplit($2,a,/[0-9][0-9]?/); $2 = sprintf("%02d/%d%d", a[1], a[2], a[3]) 1' file
                    1,01/2018,111
                    2,01/2018,111
                    3,10/2018,111


                    If Perl is an option



                    perl -F, -lpe '
                    $F[1] =~ s(dd?)-?(d+)sprintf "%02d/%d", $1, $2e;
                    $_ = join ",", @F
                    ' file






                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited Jul 3 at 21:38


























                    answered Jul 3 at 21:20









                    steeldriver

                    30.9k34877




                    30.9k34877






















                        up vote
                        0
                        down vote













                        sed -e 's/^(.),(.),(.)/2/g' -e 's/([0-9]1,2)([0-9]4)/1-2/g' file*



                        s/^(.),(.),(.*)/2/g - splits based on commas and gets 2nd value
                        s/([0-9]1,2)([0-9]4)/1-2/g - splits and inserts '-' between year and month






                        share|improve this answer



























                          up vote
                          0
                          down vote













                          sed -e 's/^(.),(.),(.)/2/g' -e 's/([0-9]1,2)([0-9]4)/1-2/g' file*



                          s/^(.),(.),(.*)/2/g - splits based on commas and gets 2nd value
                          s/([0-9]1,2)([0-9]4)/1-2/g - splits and inserts '-' between year and month






                          share|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            sed -e 's/^(.),(.),(.)/2/g' -e 's/([0-9]1,2)([0-9]4)/1-2/g' file*



                            s/^(.),(.),(.*)/2/g - splits based on commas and gets 2nd value
                            s/([0-9]1,2)([0-9]4)/1-2/g - splits and inserts '-' between year and month






                            share|improve this answer















                            sed -e 's/^(.),(.),(.)/2/g' -e 's/([0-9]1,2)([0-9]4)/1-2/g' file*



                            s/^(.),(.),(.*)/2/g - splits based on commas and gets 2nd value
                            s/([0-9]1,2)([0-9]4)/1-2/g - splits and inserts '-' between year and month







                            share|improve this answer















                            share|improve this answer



                            share|improve this answer








                            edited Jul 6 at 6:48


























                            answered Jul 6 at 5:34









                            Nisha

                            12




                            12




















                                up vote
                                0
                                down vote













                                sed -e 's/^(.),([0-9]1,2)([0-9]4),(.)/1,2-3,4/g' test.txt



                                • ^(.*), = capture until first ',' and stored in 1

                                • ([0-9]1,2) = capture 1 or 2 digit number and store in 2

                                • ([0-9]4) = capture 4 didit no and store in 3

                                • ,(.*) 4 = capture the rest from ',' and store it in 4

                                • And replace accordingly





                                share|improve this answer

























                                  up vote
                                  0
                                  down vote













                                  sed -e 's/^(.),([0-9]1,2)([0-9]4),(.)/1,2-3,4/g' test.txt



                                  • ^(.*), = capture until first ',' and stored in 1

                                  • ([0-9]1,2) = capture 1 or 2 digit number and store in 2

                                  • ([0-9]4) = capture 4 didit no and store in 3

                                  • ,(.*) 4 = capture the rest from ',' and store it in 4

                                  • And replace accordingly





                                  share|improve this answer























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    sed -e 's/^(.),([0-9]1,2)([0-9]4),(.)/1,2-3,4/g' test.txt



                                    • ^(.*), = capture until first ',' and stored in 1

                                    • ([0-9]1,2) = capture 1 or 2 digit number and store in 2

                                    • ([0-9]4) = capture 4 didit no and store in 3

                                    • ,(.*) 4 = capture the rest from ',' and store it in 4

                                    • And replace accordingly





                                    share|improve this answer













                                    sed -e 's/^(.),([0-9]1,2)([0-9]4),(.)/1,2-3,4/g' test.txt



                                    • ^(.*), = capture until first ',' and stored in 1

                                    • ([0-9]1,2) = capture 1 or 2 digit number and store in 2

                                    • ([0-9]4) = capture 4 didit no and store in 3

                                    • ,(.*) 4 = capture the rest from ',' and store it in 4

                                    • And replace accordingly






                                    share|improve this answer













                                    share|improve this answer



                                    share|improve this answer











                                    answered Jul 6 at 8:18









                                    Nisha

                                    12




                                    12






















                                         

                                        draft saved


                                        draft discarded


























                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453308%2fedit-comma-seperated-fields%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