Replace hyphen with empty string in specific column of csv












0















I have a csv file with 30 columns. I need to remove hyphen only from the 30th column.(3rd and 4th column contains hyphen but it should not be removed.)I tried below awk command to achieve it. But it is removing few records and I couldn't find the reason.



awk -f=',' 'gsub= "\-","",$30)' OFS=, input.csv > output.csv


Please suggest a solution to remove hyphens in specific column of csv without removing records.



PFB the sample input:



roll,name,type
01,j-man,re-open
01,i-man,reopen
01,j-man,reopen
01,r-man,re-open


expected output:



roll,name,type
01,j-man,reopen
01,i-man,reopen
01,j-man,reopen
01,r-man,reopen









share|improve this question

























  • put a minimal fragment of your input.csv

    – RomanPerekhrest
    Nov 20 '18 at 10:30











  • i have updated the question

    – Anupriya
    Nov 20 '18 at 11:21











  • try $(30) instead of $30

    – stack0114106
    Nov 20 '18 at 16:11
















0















I have a csv file with 30 columns. I need to remove hyphen only from the 30th column.(3rd and 4th column contains hyphen but it should not be removed.)I tried below awk command to achieve it. But it is removing few records and I couldn't find the reason.



awk -f=',' 'gsub= "\-","",$30)' OFS=, input.csv > output.csv


Please suggest a solution to remove hyphens in specific column of csv without removing records.



PFB the sample input:



roll,name,type
01,j-man,re-open
01,i-man,reopen
01,j-man,reopen
01,r-man,re-open


expected output:



roll,name,type
01,j-man,reopen
01,i-man,reopen
01,j-man,reopen
01,r-man,reopen









share|improve this question

























  • put a minimal fragment of your input.csv

    – RomanPerekhrest
    Nov 20 '18 at 10:30











  • i have updated the question

    – Anupriya
    Nov 20 '18 at 11:21











  • try $(30) instead of $30

    – stack0114106
    Nov 20 '18 at 16:11














0












0








0


1






I have a csv file with 30 columns. I need to remove hyphen only from the 30th column.(3rd and 4th column contains hyphen but it should not be removed.)I tried below awk command to achieve it. But it is removing few records and I couldn't find the reason.



awk -f=',' 'gsub= "\-","",$30)' OFS=, input.csv > output.csv


Please suggest a solution to remove hyphens in specific column of csv without removing records.



PFB the sample input:



roll,name,type
01,j-man,re-open
01,i-man,reopen
01,j-man,reopen
01,r-man,re-open


expected output:



roll,name,type
01,j-man,reopen
01,i-man,reopen
01,j-man,reopen
01,r-man,reopen









share|improve this question
















I have a csv file with 30 columns. I need to remove hyphen only from the 30th column.(3rd and 4th column contains hyphen but it should not be removed.)I tried below awk command to achieve it. But it is removing few records and I couldn't find the reason.



awk -f=',' 'gsub= "\-","",$30)' OFS=, input.csv > output.csv


Please suggest a solution to remove hyphens in specific column of csv without removing records.



PFB the sample input:



roll,name,type
01,j-man,re-open
01,i-man,reopen
01,j-man,reopen
01,r-man,re-open


expected output:



roll,name,type
01,j-man,reopen
01,i-man,reopen
01,j-man,reopen
01,r-man,reopen






shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 17:38









stack0114106

2,7811417




2,7811417










asked Nov 20 '18 at 10:23









AnupriyaAnupriya

43




43













  • put a minimal fragment of your input.csv

    – RomanPerekhrest
    Nov 20 '18 at 10:30











  • i have updated the question

    – Anupriya
    Nov 20 '18 at 11:21











  • try $(30) instead of $30

    – stack0114106
    Nov 20 '18 at 16:11



















  • put a minimal fragment of your input.csv

    – RomanPerekhrest
    Nov 20 '18 at 10:30











  • i have updated the question

    – Anupriya
    Nov 20 '18 at 11:21











  • try $(30) instead of $30

    – stack0114106
    Nov 20 '18 at 16:11

















put a minimal fragment of your input.csv

– RomanPerekhrest
Nov 20 '18 at 10:30





put a minimal fragment of your input.csv

– RomanPerekhrest
Nov 20 '18 at 10:30













i have updated the question

– Anupriya
Nov 20 '18 at 11:21





i have updated the question

– Anupriya
Nov 20 '18 at 11:21













try $(30) instead of $30

– stack0114106
Nov 20 '18 at 16:11





try $(30) instead of $30

– stack0114106
Nov 20 '18 at 16:11












1 Answer
1






active

oldest

votes


















0














I used the example to illustrate with 10th column. Replace 10 with 30 for your case



$ cat > hyphen.txt
roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
01-1,j-man,re-open,r4,r5,r6,r7,r8,r9,ab--cd,r11
01-2,i-man,reopen,r4,r5,r6,r7,r8,r9,pq--rs,r11
01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11


$ awk -F"," ' { gsub(/[-]/,"",$10); print } ' hyphen.txt
roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
01-1 j-man re-open r4 r5 r6 r7 r8 r9 abcd r11
01-2 i-man reopen r4 r5 r6 r7 r8 r9 pqrs r11
01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390889%2freplace-hyphen-with-empty-string-in-specific-column-of-csv%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I used the example to illustrate with 10th column. Replace 10 with 30 for your case



    $ cat > hyphen.txt
    roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
    01-1,j-man,re-open,r4,r5,r6,r7,r8,r9,ab--cd,r11
    01-2,i-man,reopen,r4,r5,r6,r7,r8,r9,pq--rs,r11
    01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
    01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11


    $ awk -F"," ' { gsub(/[-]/,"",$10); print } ' hyphen.txt
    roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
    01-1 j-man re-open r4 r5 r6 r7 r8 r9 abcd r11
    01-2 i-man reopen r4 r5 r6 r7 r8 r9 pqrs r11
    01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
    01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11





    share|improve this answer




























      0














      I used the example to illustrate with 10th column. Replace 10 with 30 for your case



      $ cat > hyphen.txt
      roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
      01-1,j-man,re-open,r4,r5,r6,r7,r8,r9,ab--cd,r11
      01-2,i-man,reopen,r4,r5,r6,r7,r8,r9,pq--rs,r11
      01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
      01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11


      $ awk -F"," ' { gsub(/[-]/,"",$10); print } ' hyphen.txt
      roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
      01-1 j-man re-open r4 r5 r6 r7 r8 r9 abcd r11
      01-2 i-man reopen r4 r5 r6 r7 r8 r9 pqrs r11
      01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
      01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11





      share|improve this answer


























        0












        0








        0







        I used the example to illustrate with 10th column. Replace 10 with 30 for your case



        $ cat > hyphen.txt
        roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
        01-1,j-man,re-open,r4,r5,r6,r7,r8,r9,ab--cd,r11
        01-2,i-man,reopen,r4,r5,r6,r7,r8,r9,pq--rs,r11
        01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
        01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11


        $ awk -F"," ' { gsub(/[-]/,"",$10); print } ' hyphen.txt
        roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
        01-1 j-man re-open r4 r5 r6 r7 r8 r9 abcd r11
        01-2 i-man reopen r4 r5 r6 r7 r8 r9 pqrs r11
        01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
        01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11





        share|improve this answer













        I used the example to illustrate with 10th column. Replace 10 with 30 for your case



        $ cat > hyphen.txt
        roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
        01-1,j-man,re-open,r4,r5,r6,r7,r8,r9,ab--cd,r11
        01-2,i-man,reopen,r4,r5,r6,r7,r8,r9,pq--rs,r11
        01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
        01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11


        $ awk -F"," ' { gsub(/[-]/,"",$10); print } ' hyphen.txt
        roll,name,type,col4,col5,col6,col7,col8,col9,col10,col11
        01-1 j-man re-open r4 r5 r6 r7 r8 r9 abcd r11
        01-2 i-man reopen r4 r5 r6 r7 r8 r9 pqrs r11
        01-3,j-man,reopen,r4,r5,r6,r7,r8,r9,r10,r11
        01-4,r-man,re-open,r4,r5,r6,r7,r8,r9,r10,r11






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 16:20









        stack0114106stack0114106

        2,7811417




        2,7811417






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390889%2freplace-hyphen-with-empty-string-in-specific-column-of-csv%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]