print lines with unique specified fields

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 print lines based on having unique fields 2, 3 and 4?



fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.



Input:



10,11,12,A,3
10,11,12,A,4
10,11,12,B,3


OUTPUT:



10,11,12,B,3









share|improve this question



























    up vote
    -1
    down vote

    favorite












    How to print lines based on having unique fields 2, 3 and 4?



    fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.



    Input:



    10,11,12,A,3
    10,11,12,A,4
    10,11,12,B,3


    OUTPUT:



    10,11,12,B,3









    share|improve this question

























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      How to print lines based on having unique fields 2, 3 and 4?



      fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.



      Input:



      10,11,12,A,3
      10,11,12,A,4
      10,11,12,B,3


      OUTPUT:



      10,11,12,B,3









      share|improve this question















      How to print lines based on having unique fields 2, 3 and 4?



      fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.



      Input:



      10,11,12,A,3
      10,11,12,A,4
      10,11,12,B,3


      OUTPUT:



      10,11,12,B,3






      text-processing awk uniq






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 31 at 13:49









      αғsнιη

      16k92563




      16k92563










      asked Aug 31 at 12:43









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

      417419




      417419




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          With awk:



           awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile


          Here, we are processing input infile two times, first read the file and saving each duplicated lines according to the specified fields $2, $3 and $4 into the associated array named dup; the ++ is incrementing those lines occurrences every time.



          At next process, checking and will print the entire line if the specified fields occurred only once.






          share|improve this answer





























            up vote
            0
            down vote













            For example:



            egrep '^[^,]*,11,12,B,' input.file


            Explain:



            ^ from begining of the line



            [^,] anything what is not the ','



            * as many times as possible



            ,11,12,B, that what you search for






            share|improve this answer


















            • 1




              field 2 and 3 are not static numbers.
              – msp9011
              Aug 31 at 13:05











            • Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
              – schweik
              Aug 31 at 13:22










            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%2f466029%2fprint-lines-with-unique-specified-fields%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
            3
            down vote













            With awk:



             awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile


            Here, we are processing input infile two times, first read the file and saving each duplicated lines according to the specified fields $2, $3 and $4 into the associated array named dup; the ++ is incrementing those lines occurrences every time.



            At next process, checking and will print the entire line if the specified fields occurred only once.






            share|improve this answer


























              up vote
              3
              down vote













              With awk:



               awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile


              Here, we are processing input infile two times, first read the file and saving each duplicated lines according to the specified fields $2, $3 and $4 into the associated array named dup; the ++ is incrementing those lines occurrences every time.



              At next process, checking and will print the entire line if the specified fields occurred only once.






              share|improve this answer
























                up vote
                3
                down vote










                up vote
                3
                down vote









                With awk:



                 awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile


                Here, we are processing input infile two times, first read the file and saving each duplicated lines according to the specified fields $2, $3 and $4 into the associated array named dup; the ++ is incrementing those lines occurrences every time.



                At next process, checking and will print the entire line if the specified fields occurred only once.






                share|improve this answer














                With awk:



                 awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile


                Here, we are processing input infile two times, first read the file and saving each duplicated lines according to the specified fields $2, $3 and $4 into the associated array named dup; the ++ is incrementing those lines occurrences every time.



                At next process, checking and will print the entire line if the specified fields occurred only once.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 31 at 13:57

























                answered Aug 31 at 13:11









                αғsнιη

                16k92563




                16k92563






















                    up vote
                    0
                    down vote













                    For example:



                    egrep '^[^,]*,11,12,B,' input.file


                    Explain:



                    ^ from begining of the line



                    [^,] anything what is not the ','



                    * as many times as possible



                    ,11,12,B, that what you search for






                    share|improve this answer


















                    • 1




                      field 2 and 3 are not static numbers.
                      – msp9011
                      Aug 31 at 13:05











                    • Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
                      – schweik
                      Aug 31 at 13:22














                    up vote
                    0
                    down vote













                    For example:



                    egrep '^[^,]*,11,12,B,' input.file


                    Explain:



                    ^ from begining of the line



                    [^,] anything what is not the ','



                    * as many times as possible



                    ,11,12,B, that what you search for






                    share|improve this answer


















                    • 1




                      field 2 and 3 are not static numbers.
                      – msp9011
                      Aug 31 at 13:05











                    • Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
                      – schweik
                      Aug 31 at 13:22












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    For example:



                    egrep '^[^,]*,11,12,B,' input.file


                    Explain:



                    ^ from begining of the line



                    [^,] anything what is not the ','



                    * as many times as possible



                    ,11,12,B, that what you search for






                    share|improve this answer














                    For example:



                    egrep '^[^,]*,11,12,B,' input.file


                    Explain:



                    ^ from begining of the line



                    [^,] anything what is not the ','



                    * as many times as possible



                    ,11,12,B, that what you search for







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 31 at 13:11

























                    answered Aug 31 at 13:04









                    schweik

                    1804




                    1804







                    • 1




                      field 2 and 3 are not static numbers.
                      – msp9011
                      Aug 31 at 13:05











                    • Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
                      – schweik
                      Aug 31 at 13:22












                    • 1




                      field 2 and 3 are not static numbers.
                      – msp9011
                      Aug 31 at 13:05











                    • Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
                      – schweik
                      Aug 31 at 13:22







                    1




                    1




                    field 2 and 3 are not static numbers.
                    – msp9011
                    Aug 31 at 13:05





                    field 2 and 3 are not static numbers.
                    – msp9011
                    Aug 31 at 13:05













                    Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
                    – schweik
                    Aug 31 at 13:22




                    Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the awk is the right solution. (as αғsнιη wrote)
                    – schweik
                    Aug 31 at 13:22

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466029%2fprint-lines-with-unique-specified-fields%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?