Join without removing unique lines in Linux

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 table A:



1 n m n ...
2 m n m ...
3 n m n ...
4 m n m ...
5 n m n ...


I have a table B:



1 A
3 B
5 C


I want to join the column 2 of table B with table A by matching column 1 of both tables, without removing the unique lines in table A to get the following (for no matches write a "NA"):



1 A n m n ...
2 NA m n m ...
3 B n m n ...
4 NA m n m ...
5 C n m n ...






share|improve this question


























    up vote
    1
    down vote

    favorite












    I have a table A:



    1 n m n ...
    2 m n m ...
    3 n m n ...
    4 m n m ...
    5 n m n ...


    I have a table B:



    1 A
    3 B
    5 C


    I want to join the column 2 of table B with table A by matching column 1 of both tables, without removing the unique lines in table A to get the following (for no matches write a "NA"):



    1 A n m n ...
    2 NA m n m ...
    3 B n m n ...
    4 NA m n m ...
    5 C n m n ...






    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a table A:



      1 n m n ...
      2 m n m ...
      3 n m n ...
      4 m n m ...
      5 n m n ...


      I have a table B:



      1 A
      3 B
      5 C


      I want to join the column 2 of table B with table A by matching column 1 of both tables, without removing the unique lines in table A to get the following (for no matches write a "NA"):



      1 A n m n ...
      2 NA m n m ...
      3 B n m n ...
      4 NA m n m ...
      5 C n m n ...






      share|improve this question














      I have a table A:



      1 n m n ...
      2 m n m ...
      3 n m n ...
      4 m n m ...
      5 n m n ...


      I have a table B:



      1 A
      3 B
      5 C


      I want to join the column 2 of table B with table A by matching column 1 of both tables, without removing the unique lines in table A to get the following (for no matches write a "NA"):



      1 A n m n ...
      2 NA m n m ...
      3 B n m n ...
      4 NA m n m ...
      5 C n m n ...








      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 23 at 7:26









      αғsнιη

      15.2k92462




      15.2k92462










      asked Jan 23 at 3:15









      Johnny Tam

      1208




      1208




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          From man join



           -a FILENUM
          also print unpairable lines from file FILENUM, where FILENUM is
          1 or 2, corresponding to FILE1 or FILE2

          -e EMPTY
          replace missing input fields with EMPTY


          so



          join -a1 -e 'NA' -o 0,2.2,1.2,1.3,1.4 A B
          1 A n m n
          2 NA m n m
          3 B n m n
          4 NA m n m
          5 C n m n





          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',
            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%2f418993%2fjoin-without-removing-unique-lines-in-linux%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            From man join



             -a FILENUM
            also print unpairable lines from file FILENUM, where FILENUM is
            1 or 2, corresponding to FILE1 or FILE2

            -e EMPTY
            replace missing input fields with EMPTY


            so



            join -a1 -e 'NA' -o 0,2.2,1.2,1.3,1.4 A B
            1 A n m n
            2 NA m n m
            3 B n m n
            4 NA m n m
            5 C n m n





            share|improve this answer
























              up vote
              3
              down vote



              accepted










              From man join



               -a FILENUM
              also print unpairable lines from file FILENUM, where FILENUM is
              1 or 2, corresponding to FILE1 or FILE2

              -e EMPTY
              replace missing input fields with EMPTY


              so



              join -a1 -e 'NA' -o 0,2.2,1.2,1.3,1.4 A B
              1 A n m n
              2 NA m n m
              3 B n m n
              4 NA m n m
              5 C n m n





              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                From man join



                 -a FILENUM
                also print unpairable lines from file FILENUM, where FILENUM is
                1 or 2, corresponding to FILE1 or FILE2

                -e EMPTY
                replace missing input fields with EMPTY


                so



                join -a1 -e 'NA' -o 0,2.2,1.2,1.3,1.4 A B
                1 A n m n
                2 NA m n m
                3 B n m n
                4 NA m n m
                5 C n m n





                share|improve this answer












                From man join



                 -a FILENUM
                also print unpairable lines from file FILENUM, where FILENUM is
                1 or 2, corresponding to FILE1 or FILE2

                -e EMPTY
                replace missing input fields with EMPTY


                so



                join -a1 -e 'NA' -o 0,2.2,1.2,1.3,1.4 A B
                1 A n m n
                2 NA m n m
                3 B n m n
                4 NA m n m
                5 C n m n






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 23 at 3:27









                steeldriver

                31.5k34979




                31.5k34979






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418993%2fjoin-without-removing-unique-lines-in-linux%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?