Keep all rows according to common numbers in specific columns












0














I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.



Input



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065


Output



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503


I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1' but does not seems to work










share|improve this question




















  • 1




    Does "filter" mean "keep" or "remove"?
    – Jeff Schaller
    Dec 18 at 14:27










  • It means to keep the rows. I have modified the title.
    – fusion.slope
    Dec 18 at 14:35






  • 1




    Your code has several issues, first of all you have a uuoc, then your code will match any rows where $1==$3, as you have OR condition afterwards. Then you have $10==$1, which should be $11==$1, other than that, it should work well. I added NR==1 to print the header.
    – RoVo
    Dec 18 at 14:40








  • 1




    Don't add code to the comments, use the edit button and add it to the question
    – Thor
    Dec 18 at 14:48










  • @JeffSchaller thanks I have corrected
    – fusion.slope
    Dec 18 at 15:00
















0














I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.



Input



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065


Output



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503


I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1' but does not seems to work










share|improve this question




















  • 1




    Does "filter" mean "keep" or "remove"?
    – Jeff Schaller
    Dec 18 at 14:27










  • It means to keep the rows. I have modified the title.
    – fusion.slope
    Dec 18 at 14:35






  • 1




    Your code has several issues, first of all you have a uuoc, then your code will match any rows where $1==$3, as you have OR condition afterwards. Then you have $10==$1, which should be $11==$1, other than that, it should work well. I added NR==1 to print the header.
    – RoVo
    Dec 18 at 14:40








  • 1




    Don't add code to the comments, use the edit button and add it to the question
    – Thor
    Dec 18 at 14:48










  • @JeffSchaller thanks I have corrected
    – fusion.slope
    Dec 18 at 15:00














0












0








0







I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.



Input



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065


Output



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503


I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1' but does not seems to work










share|improve this question















I have a file with 15 columns and I would like to filter the rows that have the same values in common in the columns number: 1,3,5,8,11,14. Basically the columns mass and artificial_mass need to have the same common value. For example from a table like this.



Input



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
229 1.573 229 1.597 229 1.585 231 229 1.576 231 229 1.59 233 231 12.89
229 1.905 229 2.004 229 2.186 232 230 11.919 235 233 12.91 235 233 12.929
229 2.303 229 2.139 229 2.242 238 236 0.689 238 236 0.684 238 236 0.689
229 2.59 229 2.291 229 2.365 238 236 0.803 238 236 0.796 238 236 0.788
229 2.737 229 2.484 229 5.41 239 237 0.68 239 237 0.69 239 237 0.691
229 5.398 229 2.589 229 5.593 239 237 6.961 239 237 6.959 239 237 6.966
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503
242 5.194 242 5.123 242 5.475 244 242 12.503 244 242 11.847 245 243 0.065


Output



mass    Ret_time_min    mass    Ret_time_min    mass    Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min    mass    artifical_mass  Ret_time_min
229 1.516 229 1.503 229 1.516 231 229 1.468 231 229 1.499 231 229 1.63
242 5.163 242 4.612 242 5.141 244 242 12.126 244 242 6.182 244 242 12.503


I tried with a simple line: cat My.File.txt | awk '$1==$3 || $5==$1 && $8==$1 && $10==$1 && $14==$1' but does not seems to work







text-processing awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 18 at 14:58

























asked Dec 18 at 14:24









fusion.slope

360114




360114








  • 1




    Does "filter" mean "keep" or "remove"?
    – Jeff Schaller
    Dec 18 at 14:27










  • It means to keep the rows. I have modified the title.
    – fusion.slope
    Dec 18 at 14:35






  • 1




    Your code has several issues, first of all you have a uuoc, then your code will match any rows where $1==$3, as you have OR condition afterwards. Then you have $10==$1, which should be $11==$1, other than that, it should work well. I added NR==1 to print the header.
    – RoVo
    Dec 18 at 14:40








  • 1




    Don't add code to the comments, use the edit button and add it to the question
    – Thor
    Dec 18 at 14:48










  • @JeffSchaller thanks I have corrected
    – fusion.slope
    Dec 18 at 15:00














  • 1




    Does "filter" mean "keep" or "remove"?
    – Jeff Schaller
    Dec 18 at 14:27










  • It means to keep the rows. I have modified the title.
    – fusion.slope
    Dec 18 at 14:35






  • 1




    Your code has several issues, first of all you have a uuoc, then your code will match any rows where $1==$3, as you have OR condition afterwards. Then you have $10==$1, which should be $11==$1, other than that, it should work well. I added NR==1 to print the header.
    – RoVo
    Dec 18 at 14:40








  • 1




    Don't add code to the comments, use the edit button and add it to the question
    – Thor
    Dec 18 at 14:48










  • @JeffSchaller thanks I have corrected
    – fusion.slope
    Dec 18 at 15:00








1




1




Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27




Does "filter" mean "keep" or "remove"?
– Jeff Schaller
Dec 18 at 14:27












It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35




It means to keep the rows. I have modified the title.
– fusion.slope
Dec 18 at 14:35




1




1




Your code has several issues, first of all you have a uuoc, then your code will match any rows where $1==$3, as you have OR condition afterwards. Then you have $10==$1, which should be $11==$1, other than that, it should work well. I added NR==1 to print the header.
– RoVo
Dec 18 at 14:40






Your code has several issues, first of all you have a uuoc, then your code will match any rows where $1==$3, as you have OR condition afterwards. Then you have $10==$1, which should be $11==$1, other than that, it should work well. I added NR==1 to print the header.
– RoVo
Dec 18 at 14:40






1




1




Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48




Don't add code to the comments, use the edit button and add it to the question
– Thor
Dec 18 at 14:48












@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00




@JeffSchaller thanks I have corrected
– fusion.slope
Dec 18 at 15:00










1 Answer
1






active

oldest

votes


















2














Try this,



awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file





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',
    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%2f489699%2fkeep-all-rows-according-to-common-numbers-in-specific-columns%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









    2














    Try this,



    awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file





    share|improve this answer




























      2














      Try this,



      awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file





      share|improve this answer


























        2












        2








        2






        Try this,



        awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file





        share|improve this answer














        Try this,



        awk 'NR==1 || ( $1==$3 && $1==$5 && $1==$8 && $1==$11 && $1==$14 )' file






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 18 at 14:42

























        answered Dec 18 at 14:35









        RoVo

        2,568215




        2,568215






























            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%2f489699%2fkeep-all-rows-according-to-common-numbers-in-specific-columns%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