Remove suffix from data in col 4 of csv file only (bash)

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











up vote
1
down vote

favorite












I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".



CSV FILE OUTPUT:



 DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time_1, /ai/test
321.com, Zall, Z-V, Z_all_1, /bin/usr/home
...


WANTED OUTPUT:



 DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V Asp_tent, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time, /ai/test
321.com, Zall, Z-V, Z_all, /bin/usr/home


I have tried some awk, grep, tr attempts but no luck.







share|improve this question

























    up vote
    1
    down vote

    favorite












    I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".



    CSV FILE OUTPUT:



     DOM, PRO, CONFIG, CONFIG_CALL, PATH
    xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
    abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
    123.com, Xall, X-V, X_all_time_1, /ai/test
    321.com, Zall, Z-V, Z_all_1, /bin/usr/home
    ...


    WANTED OUTPUT:



     DOM, PRO, CONFIG, CONFIG_CALL, PATH
    xyz.com, Num1, Num1-V Asp_tent, /bin/home
    abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
    123.com, Xall, X-V, X_all_time, /ai/test
    321.com, Zall, Z-V, Z_all, /bin/usr/home


    I have tried some awk, grep, tr attempts but no luck.







    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".



      CSV FILE OUTPUT:



       DOM, PRO, CONFIG, CONFIG_CALL, PATH
      xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
      abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
      123.com, Xall, X-V, X_all_time_1, /ai/test
      321.com, Zall, Z-V, Z_all_1, /bin/usr/home
      ...


      WANTED OUTPUT:



       DOM, PRO, CONFIG, CONFIG_CALL, PATH
      xyz.com, Num1, Num1-V Asp_tent, /bin/home
      abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
      123.com, Xall, X-V, X_all_time, /ai/test
      321.com, Zall, Z-V, Z_all, /bin/usr/home


      I have tried some awk, grep, tr attempts but no luck.







      share|improve this question













      I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".



      CSV FILE OUTPUT:



       DOM, PRO, CONFIG, CONFIG_CALL, PATH
      xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
      abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
      123.com, Xall, X-V, X_all_time_1, /ai/test
      321.com, Zall, Z-V, Z_all_1, /bin/usr/home
      ...


      WANTED OUTPUT:



       DOM, PRO, CONFIG, CONFIG_CALL, PATH
      xyz.com, Num1, Num1-V Asp_tent, /bin/home
      abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
      123.com, Xall, X-V, X_all_time, /ai/test
      321.com, Zall, Z-V, Z_all, /bin/usr/home


      I have tried some awk, grep, tr attempts but no luck.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 12 at 19:12









      Jeff Schaller

      30.8k846104




      30.8k846104









      asked Jul 12 at 18:59









      SSDdude

      544




      544




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote













          Using GNU awk:



          awk -F, 'sub(/_1$/,"",$4)1' OFS=, input





          share|improve this answer






























            up vote
            0
            down vote













            Using SED:



            sed -i 's/_1,/, /g' file.csv





            share|improve this answer

















            • 2




              without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
              – Jeff Schaller
              Jul 12 at 19:33










            • Yes. But I'm replacing _1, . So it do only for suffix..
              – SivaPrasath
              Jul 12 at 20:13










            • until field 2 or 3 ends in _1
              – Jeff Schaller
              Jul 12 at 20:14










            • Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
              – SSDdude
              Jul 23 at 15:17










            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%2f454965%2fremove-suffix-from-data-in-col-4-of-csv-file-only-bash%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
            5
            down vote













            Using GNU awk:



            awk -F, 'sub(/_1$/,"",$4)1' OFS=, input





            share|improve this answer



























              up vote
              5
              down vote













              Using GNU awk:



              awk -F, 'sub(/_1$/,"",$4)1' OFS=, input





              share|improve this answer

























                up vote
                5
                down vote










                up vote
                5
                down vote









                Using GNU awk:



                awk -F, 'sub(/_1$/,"",$4)1' OFS=, input





                share|improve this answer















                Using GNU awk:



                awk -F, 'sub(/_1$/,"",$4)1' OFS=, input






                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jul 12 at 19:24


























                answered Jul 12 at 19:14









                Jesse_b

                10.1k22658




                10.1k22658






















                    up vote
                    0
                    down vote













                    Using SED:



                    sed -i 's/_1,/, /g' file.csv





                    share|improve this answer

















                    • 2




                      without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
                      – Jeff Schaller
                      Jul 12 at 19:33










                    • Yes. But I'm replacing _1, . So it do only for suffix..
                      – SivaPrasath
                      Jul 12 at 20:13










                    • until field 2 or 3 ends in _1
                      – Jeff Schaller
                      Jul 12 at 20:14










                    • Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
                      – SSDdude
                      Jul 23 at 15:17














                    up vote
                    0
                    down vote













                    Using SED:



                    sed -i 's/_1,/, /g' file.csv





                    share|improve this answer

















                    • 2




                      without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
                      – Jeff Schaller
                      Jul 12 at 19:33










                    • Yes. But I'm replacing _1, . So it do only for suffix..
                      – SivaPrasath
                      Jul 12 at 20:13










                    • until field 2 or 3 ends in _1
                      – Jeff Schaller
                      Jul 12 at 20:14










                    • Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
                      – SSDdude
                      Jul 23 at 15:17












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Using SED:



                    sed -i 's/_1,/, /g' file.csv





                    share|improve this answer













                    Using SED:



                    sed -i 's/_1,/, /g' file.csv






                    share|improve this answer













                    share|improve this answer



                    share|improve this answer











                    answered Jul 12 at 19:24









                    SivaPrasath

                    3,68311636




                    3,68311636







                    • 2




                      without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
                      – Jeff Schaller
                      Jul 12 at 19:33










                    • Yes. But I'm replacing _1, . So it do only for suffix..
                      – SivaPrasath
                      Jul 12 at 20:13










                    • until field 2 or 3 ends in _1
                      – Jeff Schaller
                      Jul 12 at 20:14










                    • Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
                      – SSDdude
                      Jul 23 at 15:17












                    • 2




                      without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
                      – Jeff Schaller
                      Jul 12 at 19:33










                    • Yes. But I'm replacing _1, . So it do only for suffix..
                      – SivaPrasath
                      Jul 12 at 20:13










                    • until field 2 or 3 ends in _1
                      – Jeff Schaller
                      Jul 12 at 20:14










                    • Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
                      – SSDdude
                      Jul 23 at 15:17







                    2




                    2




                    without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
                    – Jeff Schaller
                    Jul 12 at 19:33




                    without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.
                    – Jeff Schaller
                    Jul 12 at 19:33












                    Yes. But I'm replacing _1, . So it do only for suffix..
                    – SivaPrasath
                    Jul 12 at 20:13




                    Yes. But I'm replacing _1, . So it do only for suffix..
                    – SivaPrasath
                    Jul 12 at 20:13












                    until field 2 or 3 ends in _1
                    – Jeff Schaller
                    Jul 12 at 20:14




                    until field 2 or 3 ends in _1
                    – Jeff Schaller
                    Jul 12 at 20:14












                    Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
                    – SSDdude
                    Jul 23 at 15:17




                    Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
                    – SSDdude
                    Jul 23 at 15:17












                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454965%2fremove-suffix-from-data-in-col-4-of-csv-file-only-bash%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    The Forum (Inglewood, California)

                    Palaiologos