remove comma from a specific portion of a long string

Multi tool use
Multi tool use

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











up vote
6
down vote

favorite












I have document contain very long strings represent decoded information, i want to remove , commas from the last portion of the string. For example this is one of the long strings:



 Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


I want to remove comma from the last portion of it so let me zoom in to show you how it look like:



(99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


so the final result look like this:



Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


please notice the last portion of the long string, no comma in part of it let's zoom in to see it better:



(99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


I spent hours trying to find a way to do it but I failed, would you please help me to fix these strings, thanks!










share|improve this question



























    up vote
    6
    down vote

    favorite












    I have document contain very long strings represent decoded information, i want to remove , commas from the last portion of the string. For example this is one of the long strings:



     Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


    I want to remove comma from the last portion of it so let me zoom in to show you how it look like:



    (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


    so the final result look like this:



    Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


    please notice the last portion of the long string, no comma in part of it let's zoom in to see it better:



    (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


    I spent hours trying to find a way to do it but I failed, would you please help me to fix these strings, thanks!










    share|improve this question

























      up vote
      6
      down vote

      favorite









      up vote
      6
      down vote

      favorite











      I have document contain very long strings represent decoded information, i want to remove , commas from the last portion of the string. For example this is one of the long strings:



       Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


      I want to remove comma from the last portion of it so let me zoom in to show you how it look like:



      (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


      so the final result look like this:



      Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


      please notice the last portion of the long string, no comma in part of it let's zoom in to see it better:



      (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


      I spent hours trying to find a way to do it but I failed, would you please help me to fix these strings, thanks!










      share|improve this question















      I have document contain very long strings represent decoded information, i want to remove , commas from the last portion of the string. For example this is one of the long strings:



       Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


      I want to remove comma from the last portion of it so let me zoom in to show you how it look like:



      (99990987868959,null,68,'T59 - %,Dsc,Itm-2 tax 1 Juris',4,5);


      so the final result look like this:



      Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


      please notice the last portion of the long string, no comma in part of it let's zoom in to see it better:



      (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


      I spent hours trying to find a way to do it but I failed, would you please help me to fix these strings, thanks!







      text-processing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 hours ago









      Jeff Schaller

      33.8k851113




      33.8k851113










      asked 7 hours ago









      Zahi

      181111




      181111




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          9
          down vote



          accepted










          awk -F' -vOFS=' 'gsub(","," ",$2); print'





          share|improve this answer




















          • Nice solution. Just one bug : it will work only with lines having one '...,...' field.
            – George Vasiliou
            6 hours ago











          • @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
            – simlev
            5 hours ago










          • @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
            – David Foerster
            3 hours ago


















          up vote
          2
          down vote













          Alternative solution with gnu sed:



          sed -r 's/(x27.*),(.*x27)/1 2/g' file


          x27 : ascii code of single quote '






          share|improve this answer




















          • Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
            – simlev
            5 hours ago


















          up vote
          0
          down vote













          Perl showcase:



          perl -pe "1 while s/'.*K,(?=.*')/ /" input.txt


          Output:



          Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


          Zoomed output:



          (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);





          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%2f474357%2fremove-comma-from-a-specific-portion-of-a-long-string%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
            9
            down vote



            accepted










            awk -F' -vOFS=' 'gsub(","," ",$2); print'





            share|improve this answer




















            • Nice solution. Just one bug : it will work only with lines having one '...,...' field.
              – George Vasiliou
              6 hours ago











            • @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
              – simlev
              5 hours ago










            • @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
              – David Foerster
              3 hours ago















            up vote
            9
            down vote



            accepted










            awk -F' -vOFS=' 'gsub(","," ",$2); print'





            share|improve this answer




















            • Nice solution. Just one bug : it will work only with lines having one '...,...' field.
              – George Vasiliou
              6 hours ago











            • @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
              – simlev
              5 hours ago










            • @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
              – David Foerster
              3 hours ago













            up vote
            9
            down vote



            accepted







            up vote
            9
            down vote



            accepted






            awk -F' -vOFS=' 'gsub(","," ",$2); print'





            share|improve this answer












            awk -F' -vOFS=' 'gsub(","," ",$2); print'






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 7 hours ago









            Goro

            8,13753978




            8,13753978











            • Nice solution. Just one bug : it will work only with lines having one '...,...' field.
              – George Vasiliou
              6 hours ago











            • @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
              – simlev
              5 hours ago










            • @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
              – David Foerster
              3 hours ago

















            • Nice solution. Just one bug : it will work only with lines having one '...,...' field.
              – George Vasiliou
              6 hours ago











            • @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
              – simlev
              5 hours ago










            • @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
              – David Foerster
              3 hours ago
















            Nice solution. Just one bug : it will work only with lines having one '...,...' field.
            – George Vasiliou
            6 hours ago





            Nice solution. Just one bug : it will work only with lines having one '...,...' field.
            – George Vasiliou
            6 hours ago













            @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
            – simlev
            5 hours ago




            @GeorgeVasiliou This solution can be made more general: awk -F' -vOFS=' 'for(n=1;n<=NF;n++)if(n%2==0)gsub(","," ",$n) print'.
            – simlev
            5 hours ago












            @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
            – David Foerster
            3 hours ago





            @simlev: You can omit the filter on the iteration counter if you adjust the iteration start and step size: for (n = 2; n <= NF; n += 2) gsub(",", " ", $n);
            – David Foerster
            3 hours ago













            up vote
            2
            down vote













            Alternative solution with gnu sed:



            sed -r 's/(x27.*),(.*x27)/1 2/g' file


            x27 : ascii code of single quote '






            share|improve this answer




















            • Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
              – simlev
              5 hours ago















            up vote
            2
            down vote













            Alternative solution with gnu sed:



            sed -r 's/(x27.*),(.*x27)/1 2/g' file


            x27 : ascii code of single quote '






            share|improve this answer




















            • Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
              – simlev
              5 hours ago













            up vote
            2
            down vote










            up vote
            2
            down vote









            Alternative solution with gnu sed:



            sed -r 's/(x27.*),(.*x27)/1 2/g' file


            x27 : ascii code of single quote '






            share|improve this answer












            Alternative solution with gnu sed:



            sed -r 's/(x27.*),(.*x27)/1 2/g' file


            x27 : ascii code of single quote '







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 6 hours ago









            George Vasiliou

            5,34031027




            5,34031027











            • Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
              – simlev
              5 hours ago

















            • Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
              – simlev
              5 hours ago
















            Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
            – simlev
            5 hours ago





            Nice way of working around ', but this removes only the last of the commas inside the single quotes, giving %,Dsc instead of % Dsc as was requested by the OP. I solved this issue using recursion.
            – simlev
            5 hours ago











            up vote
            0
            down vote













            Perl showcase:



            perl -pe "1 while s/'.*K,(?=.*')/ /" input.txt


            Output:



            Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


            Zoomed output:



            (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);





            share|improve this answer
























              up vote
              0
              down vote













              Perl showcase:



              perl -pe "1 while s/'.*K,(?=.*')/ /" input.txt


              Output:



              Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


              Zoomed output:



              (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Perl showcase:



                perl -pe "1 while s/'.*K,(?=.*')/ /" input.txt


                Output:



                Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


                Zoomed output:



                (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);





                share|improve this answer












                Perl showcase:



                perl -pe "1 while s/'.*K,(?=.*')/ /" input.txt


                Output:



                Insert into PE_ATRT_S(ID_ANA_TX,FQ_WQ_ASDF,ID_PRTY,NM_ATHY_TX,SC_RND,QU_DGT_RND) values (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);


                Zoomed output:



                (99990987868959,null,68,'T59 - % Dsc Itm-2 tax 1 Juris',4,5);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 5 hours ago









                simlev

                550114




                550114



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474357%2fremove-comma-from-a-specific-portion-of-a-long-string%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    eVU1klLXQxw,fRyUc3
                    7Ihkc,12JcF6Uv2yzzW 71eN,D 8GRGVs6LYSIU MHMg lo2

                    Popular posts from this blog

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

                    How many registers does an x86_64 CPU actually have?

                    Displaying single band from multi-band raster using QGIS