Extract a file containing 0|0,0|1,1|0 and 1|1












1














I have a csv file .Here is how it looks :



chr22,  Position ,  A     ,       B ,      C ,   D , E
22 , 16050115 , 0|0:404 , 0 , 0 , 0 , 1|1:5
22 ,16050213 ,0|0:403 , 0 , 0 , 0 , 3|4:6
22 , 16050607 , 1|0:340 , 1|1:3, 0 , 0 , 1|1:3
22 16050737 , 0|0:402 , 3|0:4 , 0|7:23 , 0 , 0
22 16050783 , 0|0:404 , 2|2:5 , 0|1:31 , 1|0:51, 0


0|0:404 means the count of 0|0 is 404 and so on. I would like to extract only values of 0|0,1|0,0|1 and 1:1
The output should be :



chr22, Position, A ,B, C ,D, E
22 ,16050115, 0|0:404 ,0 ,0 ,0 ,1|1:5
22 ,16050213, 0|0:403, 0 ,0, 0, 0
22 ,16050607, 1|0:340, 1|1:3, 0 ,0 ,1|1:3
22 ,16050737, 0|0:402, 0 ,0 ,0, 0
22 ,16050783, 0|0:404 ,0 ,0|1:31 ,1|0:51, 0


I tried grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1 /path/file.csv doesn't seem to work.










share|improve this question




















  • 1




    Please, don't post images of text.
    – Kusalananda
    Dec 14 at 6:46










  • png csv? doesn't really fulfill the MCVE criteria does it?
    – Thor
    Dec 14 at 6:47






  • 1




    According to your description, your grep is doing the correct thing (apart from missing a : and a single quote at the end). According to your expected output, your description of what you want to do is wrong. Please clarify either description or output.
    – Kusalananda
    Dec 14 at 7:48










  • Hi I have edited the file. The grep code doesn't work . It returns the output with values for 2|2,0|7...I want the values only for 0|0,0|1,1|0 and 1|1
    – Adhira Reddy
    Dec 14 at 7:51










  • I don't see 2|2 or 0|7 in your input?
    – tink
    Dec 14 at 8:47
















1














I have a csv file .Here is how it looks :



chr22,  Position ,  A     ,       B ,      C ,   D , E
22 , 16050115 , 0|0:404 , 0 , 0 , 0 , 1|1:5
22 ,16050213 ,0|0:403 , 0 , 0 , 0 , 3|4:6
22 , 16050607 , 1|0:340 , 1|1:3, 0 , 0 , 1|1:3
22 16050737 , 0|0:402 , 3|0:4 , 0|7:23 , 0 , 0
22 16050783 , 0|0:404 , 2|2:5 , 0|1:31 , 1|0:51, 0


0|0:404 means the count of 0|0 is 404 and so on. I would like to extract only values of 0|0,1|0,0|1 and 1:1
The output should be :



chr22, Position, A ,B, C ,D, E
22 ,16050115, 0|0:404 ,0 ,0 ,0 ,1|1:5
22 ,16050213, 0|0:403, 0 ,0, 0, 0
22 ,16050607, 1|0:340, 1|1:3, 0 ,0 ,1|1:3
22 ,16050737, 0|0:402, 0 ,0 ,0, 0
22 ,16050783, 0|0:404 ,0 ,0|1:31 ,1|0:51, 0


I tried grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1 /path/file.csv doesn't seem to work.










share|improve this question




















  • 1




    Please, don't post images of text.
    – Kusalananda
    Dec 14 at 6:46










  • png csv? doesn't really fulfill the MCVE criteria does it?
    – Thor
    Dec 14 at 6:47






  • 1




    According to your description, your grep is doing the correct thing (apart from missing a : and a single quote at the end). According to your expected output, your description of what you want to do is wrong. Please clarify either description or output.
    – Kusalananda
    Dec 14 at 7:48










  • Hi I have edited the file. The grep code doesn't work . It returns the output with values for 2|2,0|7...I want the values only for 0|0,0|1,1|0 and 1|1
    – Adhira Reddy
    Dec 14 at 7:51










  • I don't see 2|2 or 0|7 in your input?
    – tink
    Dec 14 at 8:47














1












1








1







I have a csv file .Here is how it looks :



chr22,  Position ,  A     ,       B ,      C ,   D , E
22 , 16050115 , 0|0:404 , 0 , 0 , 0 , 1|1:5
22 ,16050213 ,0|0:403 , 0 , 0 , 0 , 3|4:6
22 , 16050607 , 1|0:340 , 1|1:3, 0 , 0 , 1|1:3
22 16050737 , 0|0:402 , 3|0:4 , 0|7:23 , 0 , 0
22 16050783 , 0|0:404 , 2|2:5 , 0|1:31 , 1|0:51, 0


0|0:404 means the count of 0|0 is 404 and so on. I would like to extract only values of 0|0,1|0,0|1 and 1:1
The output should be :



chr22, Position, A ,B, C ,D, E
22 ,16050115, 0|0:404 ,0 ,0 ,0 ,1|1:5
22 ,16050213, 0|0:403, 0 ,0, 0, 0
22 ,16050607, 1|0:340, 1|1:3, 0 ,0 ,1|1:3
22 ,16050737, 0|0:402, 0 ,0 ,0, 0
22 ,16050783, 0|0:404 ,0 ,0|1:31 ,1|0:51, 0


I tried grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1 /path/file.csv doesn't seem to work.










share|improve this question















I have a csv file .Here is how it looks :



chr22,  Position ,  A     ,       B ,      C ,   D , E
22 , 16050115 , 0|0:404 , 0 , 0 , 0 , 1|1:5
22 ,16050213 ,0|0:403 , 0 , 0 , 0 , 3|4:6
22 , 16050607 , 1|0:340 , 1|1:3, 0 , 0 , 1|1:3
22 16050737 , 0|0:402 , 3|0:4 , 0|7:23 , 0 , 0
22 16050783 , 0|0:404 , 2|2:5 , 0|1:31 , 1|0:51, 0


0|0:404 means the count of 0|0 is 404 and so on. I would like to extract only values of 0|0,1|0,0|1 and 1:1
The output should be :



chr22, Position, A ,B, C ,D, E
22 ,16050115, 0|0:404 ,0 ,0 ,0 ,1|1:5
22 ,16050213, 0|0:403, 0 ,0, 0, 0
22 ,16050607, 1|0:340, 1|1:3, 0 ,0 ,1|1:3
22 ,16050737, 0|0:402, 0 ,0 ,0, 0
22 ,16050783, 0|0:404 ,0 ,0|1:31 ,1|0:51, 0


I tried grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1 /path/file.csv doesn't seem to work.







grep wildcards






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 14 at 10:46









roaima

42.8k551116




42.8k551116










asked Dec 14 at 6:32









Adhira Reddy

83




83








  • 1




    Please, don't post images of text.
    – Kusalananda
    Dec 14 at 6:46










  • png csv? doesn't really fulfill the MCVE criteria does it?
    – Thor
    Dec 14 at 6:47






  • 1




    According to your description, your grep is doing the correct thing (apart from missing a : and a single quote at the end). According to your expected output, your description of what you want to do is wrong. Please clarify either description or output.
    – Kusalananda
    Dec 14 at 7:48










  • Hi I have edited the file. The grep code doesn't work . It returns the output with values for 2|2,0|7...I want the values only for 0|0,0|1,1|0 and 1|1
    – Adhira Reddy
    Dec 14 at 7:51










  • I don't see 2|2 or 0|7 in your input?
    – tink
    Dec 14 at 8:47














  • 1




    Please, don't post images of text.
    – Kusalananda
    Dec 14 at 6:46










  • png csv? doesn't really fulfill the MCVE criteria does it?
    – Thor
    Dec 14 at 6:47






  • 1




    According to your description, your grep is doing the correct thing (apart from missing a : and a single quote at the end). According to your expected output, your description of what you want to do is wrong. Please clarify either description or output.
    – Kusalananda
    Dec 14 at 7:48










  • Hi I have edited the file. The grep code doesn't work . It returns the output with values for 2|2,0|7...I want the values only for 0|0,0|1,1|0 and 1|1
    – Adhira Reddy
    Dec 14 at 7:51










  • I don't see 2|2 or 0|7 in your input?
    – tink
    Dec 14 at 8:47








1




1




Please, don't post images of text.
– Kusalananda
Dec 14 at 6:46




Please, don't post images of text.
– Kusalananda
Dec 14 at 6:46












png csv? doesn't really fulfill the MCVE criteria does it?
– Thor
Dec 14 at 6:47




png csv? doesn't really fulfill the MCVE criteria does it?
– Thor
Dec 14 at 6:47




1




1




According to your description, your grep is doing the correct thing (apart from missing a : and a single quote at the end). According to your expected output, your description of what you want to do is wrong. Please clarify either description or output.
– Kusalananda
Dec 14 at 7:48




According to your description, your grep is doing the correct thing (apart from missing a : and a single quote at the end). According to your expected output, your description of what you want to do is wrong. Please clarify either description or output.
– Kusalananda
Dec 14 at 7:48












Hi I have edited the file. The grep code doesn't work . It returns the output with values for 2|2,0|7...I want the values only for 0|0,0|1,1|0 and 1|1
– Adhira Reddy
Dec 14 at 7:51




Hi I have edited the file. The grep code doesn't work . It returns the output with values for 2|2,0|7...I want the values only for 0|0,0|1,1|0 and 1|1
– Adhira Reddy
Dec 14 at 7:51












I don't see 2|2 or 0|7 in your input?
– tink
Dec 14 at 8:47




I don't see 2|2 or 0|7 in your input?
– tink
Dec 14 at 8:47










3 Answers
3






active

oldest

votes


















2














Original command lines



I think the following command line will do it with a comma separated file by skipping 'offending' lines,



grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv




You can check with a small file with color,



grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'


and which lines are found by grep (excluded in the previous command lines by the option -v),



grep -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'




The following command line will do it with a tab separated file,



grep -v -e 't[2-9]|' -e '|[2-9]:' Reddy.tab


or if you want a slightly looser check, the following command line can work,



grep -v -e '[2-9]|' -e '|[2-9]:' Reddy.tab file.csv


Command line in response to a comment by the OP



I think the following command line will do what the OP wants with comma separated files as well as tab separated files,



sed -e 's/[2-9]|[0-9]:[0-9]*/NA/' -e 's/[0-9]|[2-9]:[0-9]*/NA/' file.csv





share|improve this answer























  • grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
    – Adhira Reddy
    Dec 14 at 7:53










  • @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
    – sudodus
    Dec 14 at 7:55








  • 1




    Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
    – Adhira Reddy
    Dec 14 at 8:00










  • @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
    – sudodus
    Dec 14 at 8:15










  • @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
    – sudodus
    Dec 14 at 8:29





















1














Not sure if grep is a requirement for this case, but using perl, you could do something like this to remove the unwanted items:



perl -pe 's/, ?[2-9]d*|d+:d+//g; s/, ?d+|[2-9]d*:d+//g' /path/to/file.csv






share|improve this answer































    0














    I would try



    grep -e '[01]|[01]:' 


    where | need to be escaped, as 0|1 means either 0 or 1.



    note that



    grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1:'


    match the same.



    filtering on a column :



    awk -F, '$3 ~/[01]|[01]:/ '


    where $3 is third column.



    filtering column 3 and above



    awk -F, '{printf "%s,%s",$1,$2 ; 
    for(i=3;i<=NF;i++)
    if ( $i ~ /[01]|[01]:/)
    printf ",%s",$i ;
    printf "n" }'


    that can be one lined.




    • note that | in this case, need to be escaped.


    • note also that first line is filtered out



      chr22,Position
      22,16050115,0|0:404,1|1:5
      22,16050213,0|0:403
      22,16050607,1|0:340,1|1:3,1|1:3
      22,16050737,0|0:402
      22,16050783,0|0:404,0|1:31,1|0:51







    share|improve this answer























    • It doesnt work .I tried both the codes
      – Adhira Reddy
      Dec 14 at 7:55











    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f487912%2fextract-a-file-containing-00-01-10-and-11%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Original command lines



    I think the following command line will do it with a comma separated file by skipping 'offending' lines,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv




    You can check with a small file with color,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'


    and which lines are found by grep (excluded in the previous command lines by the option -v),



    grep -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'




    The following command line will do it with a tab separated file,



    grep -v -e 't[2-9]|' -e '|[2-9]:' Reddy.tab


    or if you want a slightly looser check, the following command line can work,



    grep -v -e '[2-9]|' -e '|[2-9]:' Reddy.tab file.csv


    Command line in response to a comment by the OP



    I think the following command line will do what the OP wants with comma separated files as well as tab separated files,



    sed -e 's/[2-9]|[0-9]:[0-9]*/NA/' -e 's/[0-9]|[2-9]:[0-9]*/NA/' file.csv





    share|improve this answer























    • grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
      – Adhira Reddy
      Dec 14 at 7:53










    • @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
      – sudodus
      Dec 14 at 7:55








    • 1




      Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
      – Adhira Reddy
      Dec 14 at 8:00










    • @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
      – sudodus
      Dec 14 at 8:15










    • @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
      – sudodus
      Dec 14 at 8:29


















    2














    Original command lines



    I think the following command line will do it with a comma separated file by skipping 'offending' lines,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv




    You can check with a small file with color,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'


    and which lines are found by grep (excluded in the previous command lines by the option -v),



    grep -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'




    The following command line will do it with a tab separated file,



    grep -v -e 't[2-9]|' -e '|[2-9]:' Reddy.tab


    or if you want a slightly looser check, the following command line can work,



    grep -v -e '[2-9]|' -e '|[2-9]:' Reddy.tab file.csv


    Command line in response to a comment by the OP



    I think the following command line will do what the OP wants with comma separated files as well as tab separated files,



    sed -e 's/[2-9]|[0-9]:[0-9]*/NA/' -e 's/[0-9]|[2-9]:[0-9]*/NA/' file.csv





    share|improve this answer























    • grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
      – Adhira Reddy
      Dec 14 at 7:53










    • @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
      – sudodus
      Dec 14 at 7:55








    • 1




      Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
      – Adhira Reddy
      Dec 14 at 8:00










    • @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
      – sudodus
      Dec 14 at 8:15










    • @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
      – sudodus
      Dec 14 at 8:29
















    2












    2








    2






    Original command lines



    I think the following command line will do it with a comma separated file by skipping 'offending' lines,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv




    You can check with a small file with color,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'


    and which lines are found by grep (excluded in the previous command lines by the option -v),



    grep -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'




    The following command line will do it with a tab separated file,



    grep -v -e 't[2-9]|' -e '|[2-9]:' Reddy.tab


    or if you want a slightly looser check, the following command line can work,



    grep -v -e '[2-9]|' -e '|[2-9]:' Reddy.tab file.csv


    Command line in response to a comment by the OP



    I think the following command line will do what the OP wants with comma separated files as well as tab separated files,



    sed -e 's/[2-9]|[0-9]:[0-9]*/NA/' -e 's/[0-9]|[2-9]:[0-9]*/NA/' file.csv





    share|improve this answer














    Original command lines



    I think the following command line will do it with a comma separated file by skipping 'offending' lines,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv




    You can check with a small file with color,



    grep -v -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'


    and which lines are found by grep (excluded in the previous command lines by the option -v),



    grep -e ', *[2-9]|' -e '|[2-9]:' file.csv |grep --color '.|.'




    The following command line will do it with a tab separated file,



    grep -v -e 't[2-9]|' -e '|[2-9]:' Reddy.tab


    or if you want a slightly looser check, the following command line can work,



    grep -v -e '[2-9]|' -e '|[2-9]:' Reddy.tab file.csv


    Command line in response to a comment by the OP



    I think the following command line will do what the OP wants with comma separated files as well as tab separated files,



    sed -e 's/[2-9]|[0-9]:[0-9]*/NA/' -e 's/[0-9]|[2-9]:[0-9]*/NA/' file.csv






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 20 at 14:19

























    answered Dec 14 at 7:15









    sudodus

    96116




    96116












    • grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
      – Adhira Reddy
      Dec 14 at 7:53










    • @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
      – sudodus
      Dec 14 at 7:55








    • 1




      Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
      – Adhira Reddy
      Dec 14 at 8:00










    • @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
      – sudodus
      Dec 14 at 8:15










    • @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
      – sudodus
      Dec 14 at 8:29




















    • grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
      – Adhira Reddy
      Dec 14 at 7:53










    • @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
      – sudodus
      Dec 14 at 7:55








    • 1




      Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
      – Adhira Reddy
      Dec 14 at 8:00










    • @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
      – sudodus
      Dec 14 at 8:15










    • @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
      – sudodus
      Dec 14 at 8:29


















    grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
    – Adhira Reddy
    Dec 14 at 7:53




    grep -v -e ',[2-9]|' -e '|[2-9]:' file.csv .I tried this but still it returns values for 2|2,0|7 ..
    – Adhira Reddy
    Dec 14 at 7:53












    @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
    – sudodus
    Dec 14 at 7:55






    @AdhiraReddy, 1. Is the file comma separated file.csv or space separated as your new illustration? 2. Can there be numbers greater than 9 in the expression num1|num2?
    – sudodus
    Dec 14 at 7:55






    1




    1




    Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
    – Adhira Reddy
    Dec 14 at 8:00




    Sorry I have edited my post again. Ya my file is csv. No the numbers are less than 9
    – Adhira Reddy
    Dec 14 at 8:00












    @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
    – sudodus
    Dec 14 at 8:15




    @AdhiraReddy, It seems your file is tab separated. Please try with the command lines, that I have added to the answer.
    – sudodus
    Dec 14 at 8:15












    @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
    – sudodus
    Dec 14 at 8:29






    @AdhiraReddy, I have modified the first command for comma separated files to allow for spaces near the commas.
    – sudodus
    Dec 14 at 8:29















    1














    Not sure if grep is a requirement for this case, but using perl, you could do something like this to remove the unwanted items:



    perl -pe 's/, ?[2-9]d*|d+:d+//g; s/, ?d+|[2-9]d*:d+//g' /path/to/file.csv






    share|improve this answer




























      1














      Not sure if grep is a requirement for this case, but using perl, you could do something like this to remove the unwanted items:



      perl -pe 's/, ?[2-9]d*|d+:d+//g; s/, ?d+|[2-9]d*:d+//g' /path/to/file.csv






      share|improve this answer


























        1












        1








        1






        Not sure if grep is a requirement for this case, but using perl, you could do something like this to remove the unwanted items:



        perl -pe 's/, ?[2-9]d*|d+:d+//g; s/, ?d+|[2-9]d*:d+//g' /path/to/file.csv






        share|improve this answer














        Not sure if grep is a requirement for this case, but using perl, you could do something like this to remove the unwanted items:



        perl -pe 's/, ?[2-9]d*|d+:d+//g; s/, ?d+|[2-9]d*:d+//g' /path/to/file.csv







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 14 at 9:05

























        answered Dec 14 at 8:59









        user234931

        33115




        33115























            0














            I would try



            grep -e '[01]|[01]:' 


            where | need to be escaped, as 0|1 means either 0 or 1.



            note that



            grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1:'


            match the same.



            filtering on a column :



            awk -F, '$3 ~/[01]|[01]:/ '


            where $3 is third column.



            filtering column 3 and above



            awk -F, '{printf "%s,%s",$1,$2 ; 
            for(i=3;i<=NF;i++)
            if ( $i ~ /[01]|[01]:/)
            printf ",%s",$i ;
            printf "n" }'


            that can be one lined.




            • note that | in this case, need to be escaped.


            • note also that first line is filtered out



              chr22,Position
              22,16050115,0|0:404,1|1:5
              22,16050213,0|0:403
              22,16050607,1|0:340,1|1:3,1|1:3
              22,16050737,0|0:402
              22,16050783,0|0:404,0|1:31,1|0:51







            share|improve this answer























            • It doesnt work .I tried both the codes
              – Adhira Reddy
              Dec 14 at 7:55
















            0














            I would try



            grep -e '[01]|[01]:' 


            where | need to be escaped, as 0|1 means either 0 or 1.



            note that



            grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1:'


            match the same.



            filtering on a column :



            awk -F, '$3 ~/[01]|[01]:/ '


            where $3 is third column.



            filtering column 3 and above



            awk -F, '{printf "%s,%s",$1,$2 ; 
            for(i=3;i<=NF;i++)
            if ( $i ~ /[01]|[01]:/)
            printf ",%s",$i ;
            printf "n" }'


            that can be one lined.




            • note that | in this case, need to be escaped.


            • note also that first line is filtered out



              chr22,Position
              22,16050115,0|0:404,1|1:5
              22,16050213,0|0:403
              22,16050607,1|0:340,1|1:3,1|1:3
              22,16050737,0|0:402
              22,16050783,0|0:404,0|1:31,1|0:51







            share|improve this answer























            • It doesnt work .I tried both the codes
              – Adhira Reddy
              Dec 14 at 7:55














            0












            0








            0






            I would try



            grep -e '[01]|[01]:' 


            where | need to be escaped, as 0|1 means either 0 or 1.



            note that



            grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1:'


            match the same.



            filtering on a column :



            awk -F, '$3 ~/[01]|[01]:/ '


            where $3 is third column.



            filtering column 3 and above



            awk -F, '{printf "%s,%s",$1,$2 ; 
            for(i=3;i<=NF;i++)
            if ( $i ~ /[01]|[01]:/)
            printf ",%s",$i ;
            printf "n" }'


            that can be one lined.




            • note that | in this case, need to be escaped.


            • note also that first line is filtered out



              chr22,Position
              22,16050115,0|0:404,1|1:5
              22,16050213,0|0:403
              22,16050607,1|0:340,1|1:3,1|1:3
              22,16050737,0|0:402
              22,16050783,0|0:404,0|1:31,1|0:51







            share|improve this answer














            I would try



            grep -e '[01]|[01]:' 


            where | need to be escaped, as 0|1 means either 0 or 1.



            note that



            grep -e '0|0:' -e '1|1:' -e '0|1:' -e '1|1:'


            match the same.



            filtering on a column :



            awk -F, '$3 ~/[01]|[01]:/ '


            where $3 is third column.



            filtering column 3 and above



            awk -F, '{printf "%s,%s",$1,$2 ; 
            for(i=3;i<=NF;i++)
            if ( $i ~ /[01]|[01]:/)
            printf ",%s",$i ;
            printf "n" }'


            that can be one lined.




            • note that | in this case, need to be escaped.


            • note also that first line is filtered out



              chr22,Position
              22,16050115,0|0:404,1|1:5
              22,16050213,0|0:403
              22,16050607,1|0:340,1|1:3,1|1:3
              22,16050737,0|0:402
              22,16050783,0|0:404,0|1:31,1|0:51








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 14 at 9:14

























            answered Dec 14 at 6:38









            Archemar

            19.6k93570




            19.6k93570












            • It doesnt work .I tried both the codes
              – Adhira Reddy
              Dec 14 at 7:55


















            • It doesnt work .I tried both the codes
              – Adhira Reddy
              Dec 14 at 7:55
















            It doesnt work .I tried both the codes
            – Adhira Reddy
            Dec 14 at 7:55




            It doesnt work .I tried both the codes
            – Adhira Reddy
            Dec 14 at 7:55


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2funix.stackexchange.com%2fquestions%2f487912%2fextract-a-file-containing-00-01-10-and-11%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

            Morgemoulin

            Scott Moir

            Souastre