Replace special characters in specific 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 replace special character in specific field?



INPUT



xxxx,11/2019,xxx



OUTPUT



xxxx,11,2019,xxx



As you see that am looking to replace / with , in $2 only.



So kindly explain for me your command to achieve that.



Regards,







share|improve this question
























    up vote
    -1
    down vote

    favorite












    how to replace special character in specific field?



    INPUT



    xxxx,11/2019,xxx



    OUTPUT



    xxxx,11,2019,xxx



    As you see that am looking to replace / with , in $2 only.



    So kindly explain for me your command to achieve that.



    Regards,







    share|improve this question






















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      how to replace special character in specific field?



      INPUT



      xxxx,11/2019,xxx



      OUTPUT



      xxxx,11,2019,xxx



      As you see that am looking to replace / with , in $2 only.



      So kindly explain for me your command to achieve that.



      Regards,







      share|improve this question












      how to replace special character in specific field?



      INPUT



      xxxx,11/2019,xxx



      OUTPUT



      xxxx,11,2019,xxx



      As you see that am looking to replace / with , in $2 only.



      So kindly explain for me your command to achieve that.



      Regards,









      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 24 '17 at 8:40









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

      407418




      407418




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          awk -F, -v OFS=, 'gsub(///,",",$2); print'


          This uses awk's gsub() function to do a global regexp search and replace on field 2.



          If you want to replace only the first occurence of / in $2, use sub() rather than gsub().



          NOTE: the default output field separator OFS is a space. You need to set it to , (same as the input field separator FS), otherwise the print will output all the fields with spaces separating them.



          From the man page for GNU awk:




          gsub(r, s [, t])



          For each substring matching the regular expression r in the string
          t, substitute the string s, and return the number of substitutions.



          If t is not supplied, use $0.



          An & in the replacement text is replaced with the text that was
          actually matched.



          Use & to get a literal &. (This must be typed as \&; see GAWK:
          Effective AWK Programming for a fuller discussion of the rules for
          &'s and backslashes in the replacement text of sub(), gsub(), and
          gensub().)







          share|improve this answer





























            up vote
            0
            down vote













            The command given in the previous answer can be much simpler. Tested and working fine.



            Since changes need to be done in second column, I have added the same content in a second column and tested.



            echo "echo "xxxx,11/2019,xxx xxxx,11/2019,xxx" " |
            awk 'print gsub("/",",",$2);print $0'


            Output:



            xxxx,11/2019,xxx xxxx,11,2019,xxx





            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%2f412780%2freplace-special-characters-in-specific-field%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



              accepted










              awk -F, -v OFS=, 'gsub(///,",",$2); print'


              This uses awk's gsub() function to do a global regexp search and replace on field 2.



              If you want to replace only the first occurence of / in $2, use sub() rather than gsub().



              NOTE: the default output field separator OFS is a space. You need to set it to , (same as the input field separator FS), otherwise the print will output all the fields with spaces separating them.



              From the man page for GNU awk:




              gsub(r, s [, t])



              For each substring matching the regular expression r in the string
              t, substitute the string s, and return the number of substitutions.



              If t is not supplied, use $0.



              An & in the replacement text is replaced with the text that was
              actually matched.



              Use & to get a literal &. (This must be typed as \&; see GAWK:
              Effective AWK Programming for a fuller discussion of the rules for
              &'s and backslashes in the replacement text of sub(), gsub(), and
              gensub().)







              share|improve this answer


























                up vote
                2
                down vote



                accepted










                awk -F, -v OFS=, 'gsub(///,",",$2); print'


                This uses awk's gsub() function to do a global regexp search and replace on field 2.



                If you want to replace only the first occurence of / in $2, use sub() rather than gsub().



                NOTE: the default output field separator OFS is a space. You need to set it to , (same as the input field separator FS), otherwise the print will output all the fields with spaces separating them.



                From the man page for GNU awk:




                gsub(r, s [, t])



                For each substring matching the regular expression r in the string
                t, substitute the string s, and return the number of substitutions.



                If t is not supplied, use $0.



                An & in the replacement text is replaced with the text that was
                actually matched.



                Use & to get a literal &. (This must be typed as \&; see GAWK:
                Effective AWK Programming for a fuller discussion of the rules for
                &'s and backslashes in the replacement text of sub(), gsub(), and
                gensub().)







                share|improve this answer
























                  up vote
                  2
                  down vote



                  accepted







                  up vote
                  2
                  down vote



                  accepted






                  awk -F, -v OFS=, 'gsub(///,",",$2); print'


                  This uses awk's gsub() function to do a global regexp search and replace on field 2.



                  If you want to replace only the first occurence of / in $2, use sub() rather than gsub().



                  NOTE: the default output field separator OFS is a space. You need to set it to , (same as the input field separator FS), otherwise the print will output all the fields with spaces separating them.



                  From the man page for GNU awk:




                  gsub(r, s [, t])



                  For each substring matching the regular expression r in the string
                  t, substitute the string s, and return the number of substitutions.



                  If t is not supplied, use $0.



                  An & in the replacement text is replaced with the text that was
                  actually matched.



                  Use & to get a literal &. (This must be typed as \&; see GAWK:
                  Effective AWK Programming for a fuller discussion of the rules for
                  &'s and backslashes in the replacement text of sub(), gsub(), and
                  gensub().)







                  share|improve this answer














                  awk -F, -v OFS=, 'gsub(///,",",$2); print'


                  This uses awk's gsub() function to do a global regexp search and replace on field 2.



                  If you want to replace only the first occurence of / in $2, use sub() rather than gsub().



                  NOTE: the default output field separator OFS is a space. You need to set it to , (same as the input field separator FS), otherwise the print will output all the fields with spaces separating them.



                  From the man page for GNU awk:




                  gsub(r, s [, t])



                  For each substring matching the regular expression r in the string
                  t, substitute the string s, and return the number of substitutions.



                  If t is not supplied, use $0.



                  An & in the replacement text is replaced with the text that was
                  actually matched.



                  Use & to get a literal &. (This must be typed as \&; see GAWK:
                  Effective AWK Programming for a fuller discussion of the rules for
                  &'s and backslashes in the replacement text of sub(), gsub(), and
                  gensub().)








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 24 '17 at 8:54

























                  answered Dec 24 '17 at 8:43









                  cas

                  37.7k44394




                  37.7k44394






















                      up vote
                      0
                      down vote













                      The command given in the previous answer can be much simpler. Tested and working fine.



                      Since changes need to be done in second column, I have added the same content in a second column and tested.



                      echo "echo "xxxx,11/2019,xxx xxxx,11/2019,xxx" " |
                      awk 'print gsub("/",",",$2);print $0'


                      Output:



                      xxxx,11/2019,xxx xxxx,11,2019,xxx





                      share|improve this answer


























                        up vote
                        0
                        down vote













                        The command given in the previous answer can be much simpler. Tested and working fine.



                        Since changes need to be done in second column, I have added the same content in a second column and tested.



                        echo "echo "xxxx,11/2019,xxx xxxx,11/2019,xxx" " |
                        awk 'print gsub("/",",",$2);print $0'


                        Output:



                        xxxx,11/2019,xxx xxxx,11,2019,xxx





                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          The command given in the previous answer can be much simpler. Tested and working fine.



                          Since changes need to be done in second column, I have added the same content in a second column and tested.



                          echo "echo "xxxx,11/2019,xxx xxxx,11/2019,xxx" " |
                          awk 'print gsub("/",",",$2);print $0'


                          Output:



                          xxxx,11/2019,xxx xxxx,11,2019,xxx





                          share|improve this answer














                          The command given in the previous answer can be much simpler. Tested and working fine.



                          Since changes need to be done in second column, I have added the same content in a second column and tested.



                          echo "echo "xxxx,11/2019,xxx xxxx,11/2019,xxx" " |
                          awk 'print gsub("/",",",$2);print $0'


                          Output:



                          xxxx,11/2019,xxx xxxx,11,2019,xxx






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 5 at 13:41









                          grg

                          1857




                          1857










                          answered Dec 24 '17 at 11:50









                          Praveen Kumar BS

                          1,010128




                          1,010128






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412780%2freplace-special-characters-in-specific-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?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?