opposite of join -v?Join, filling in missing key valuescomparing column values between two Unix filesRead a...

Can elves trance in armor without any downsides?

What is Ferb's name short for?

Could an American state survive nuclear war?

How do I get my boyfriend to remove pictures of his ex girlfriend hanging in his apartment?

Why were germanium diodes so fast and germanium transisters so slow?

Russian Caesar cipher

Charges from Dollar General have never shown up on my debit card. How can I resolve this?

What happens when supercritical fuel tanks deplete below critical point?

Stare long enough and you will have found the answer

Did the US push the Kurds to lower their defences against Turkey in the months preceding the latest Turkish military operation against them?

Rent a car for a day and leave it in another city in Italy

Why do some audio amps use AC while others use DC

Car as a good investment

How does a ball bearing door hinge work?

Why doesn't hot charcoal glow blue?

How to increment the value of a (decimal) variable (with leading zero) by +1?

How to figure out key from key signature?

Is it unusual that English uses possessive for past tense?

How can you tell apart the pronounciation at the end between the "meine" and "meiner" in the daily spoken situation?

Did I Traumatize My Puppy?

What fantasy book has twins (except one's blue) and a cloaked ice bear on the cover?

Does code obfuscation give any measurable security benefit?

Are my triangles similar?

Can an idea be a being?



opposite of join -v?


Join, filling in missing key valuescomparing column values between two Unix filesRead a column from a file and append a specific column of another fileReplace field in one file based on match with a different field in another fileMatch specific columns to another fileMerge multiple files with joinDelete lines from one file if they contain a regex of content in another filepreserving field order in a 'join'Join two files based on a common field






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








2

















I have to do just the opposite of join -v1 fileA fileB, which says: print lines from fileA whose first fields do not match the first field of any line from fileB. Instead, I want to write the lines from fileA that do coincide (on their first fields) with lines from fileB.



I have tried to make join -o 1.1 2.1 fileA fileB, but this duplicates the lines that coincide, not write the line of the first file if same.



What is the easiest way?










share|improve this question
























  • 2





    join fileA <(awk '{print $1}' fileB)

    – Satō Katsura
    Aug 4 '16 at 13:22




















2

















I have to do just the opposite of join -v1 fileA fileB, which says: print lines from fileA whose first fields do not match the first field of any line from fileB. Instead, I want to write the lines from fileA that do coincide (on their first fields) with lines from fileB.



I have tried to make join -o 1.1 2.1 fileA fileB, but this duplicates the lines that coincide, not write the line of the first file if same.



What is the easiest way?










share|improve this question
























  • 2





    join fileA <(awk '{print $1}' fileB)

    – Satō Katsura
    Aug 4 '16 at 13:22
















2












2








2


1






I have to do just the opposite of join -v1 fileA fileB, which says: print lines from fileA whose first fields do not match the first field of any line from fileB. Instead, I want to write the lines from fileA that do coincide (on their first fields) with lines from fileB.



I have tried to make join -o 1.1 2.1 fileA fileB, but this duplicates the lines that coincide, not write the line of the first file if same.



What is the easiest way?










share|improve this question

















I have to do just the opposite of join -v1 fileA fileB, which says: print lines from fileA whose first fields do not match the first field of any line from fileB. Instead, I want to write the lines from fileA that do coincide (on their first fields) with lines from fileB.



I have tried to make join -o 1.1 2.1 fileA fileB, but this duplicates the lines that coincide, not write the line of the first file if same.



What is the easiest way?







text-processing join






share|improve this question
















share|improve this question













share|improve this question




share|improve this question








edited Apr 12 '18 at 0:44









Jeff Schaller

50.3k11 gold badges74 silver badges167 bronze badges




50.3k11 gold badges74 silver badges167 bronze badges










asked Aug 4 '16 at 13:17









cloudy_fogcloudy_fog

443 bronze badges




443 bronze badges











  • 2





    join fileA <(awk '{print $1}' fileB)

    – Satō Katsura
    Aug 4 '16 at 13:22
















  • 2





    join fileA <(awk '{print $1}' fileB)

    – Satō Katsura
    Aug 4 '16 at 13:22










2




2





join fileA <(awk '{print $1}' fileB)

– Satō Katsura
Aug 4 '16 at 13:22







join fileA <(awk '{print $1}' fileB)

– Satō Katsura
Aug 4 '16 at 13:22












2 Answers
2






active

oldest

votes


















1


















As Satō Katsura commented, you could "trick" join into seeing only field 1 from fileB, then ask it to do a normal join; this prints the line from fileA and the (empty) remainder of the line in (the tricked) fileB:



join fileA <(awk '{print $1}' fileB)


Given input files of:



$ cat fileA
1 blah
2 foo
3 bar

$ cat fileB
3 barely
4 baz
5 qux


The resulting output is:



$ join fileA <(awk '{print $1}' fileB)
3 bar


Wildcard pointed out that you can do this more directly (avoiding a process substitution), by piping awk's output to join:



awk '{print $1}' fileB | join fileA -





share|improve this answer




































    0


















    If the two files are sorted, you can use comm like this to display the lines from fileA that are not in fileB:



    comm -23 fileA fileB


    Or did you also want the lines in fileB that are not in fileA?






    share|improve this answer






















    • 1





      Nope, comm works with whole lines, the OP wants to compare only the first column.

      – Satō Katsura
      Aug 4 '16 at 15:44











    • yes, that is right. thank you nevertheless

      – cloudy_fog
      Aug 4 '16 at 15:45











    • @Sato there's nothing in the question that refers to fields. Everything there says lines.

      – roaima
      Aug 4 '16 at 15:48






    • 1





      join works works with fields.

      – Satō Katsura
      Aug 4 '16 at 15:50













    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/4.0/"u003ecc by-sa 4.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%2f301279%2fopposite-of-join-v%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown


























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1


















    As Satō Katsura commented, you could "trick" join into seeing only field 1 from fileB, then ask it to do a normal join; this prints the line from fileA and the (empty) remainder of the line in (the tricked) fileB:



    join fileA <(awk '{print $1}' fileB)


    Given input files of:



    $ cat fileA
    1 blah
    2 foo
    3 bar

    $ cat fileB
    3 barely
    4 baz
    5 qux


    The resulting output is:



    $ join fileA <(awk '{print $1}' fileB)
    3 bar


    Wildcard pointed out that you can do this more directly (avoiding a process substitution), by piping awk's output to join:



    awk '{print $1}' fileB | join fileA -





    share|improve this answer

































      1


















      As Satō Katsura commented, you could "trick" join into seeing only field 1 from fileB, then ask it to do a normal join; this prints the line from fileA and the (empty) remainder of the line in (the tricked) fileB:



      join fileA <(awk '{print $1}' fileB)


      Given input files of:



      $ cat fileA
      1 blah
      2 foo
      3 bar

      $ cat fileB
      3 barely
      4 baz
      5 qux


      The resulting output is:



      $ join fileA <(awk '{print $1}' fileB)
      3 bar


      Wildcard pointed out that you can do this more directly (avoiding a process substitution), by piping awk's output to join:



      awk '{print $1}' fileB | join fileA -





      share|improve this answer































        1














        1










        1









        As Satō Katsura commented, you could "trick" join into seeing only field 1 from fileB, then ask it to do a normal join; this prints the line from fileA and the (empty) remainder of the line in (the tricked) fileB:



        join fileA <(awk '{print $1}' fileB)


        Given input files of:



        $ cat fileA
        1 blah
        2 foo
        3 bar

        $ cat fileB
        3 barely
        4 baz
        5 qux


        The resulting output is:



        $ join fileA <(awk '{print $1}' fileB)
        3 bar


        Wildcard pointed out that you can do this more directly (avoiding a process substitution), by piping awk's output to join:



        awk '{print $1}' fileB | join fileA -





        share|improve this answer
















        As Satō Katsura commented, you could "trick" join into seeing only field 1 from fileB, then ask it to do a normal join; this prints the line from fileA and the (empty) remainder of the line in (the tricked) fileB:



        join fileA <(awk '{print $1}' fileB)


        Given input files of:



        $ cat fileA
        1 blah
        2 foo
        3 bar

        $ cat fileB
        3 barely
        4 baz
        5 qux


        The resulting output is:



        $ join fileA <(awk '{print $1}' fileB)
        3 bar


        Wildcard pointed out that you can do this more directly (avoiding a process substitution), by piping awk's output to join:



        awk '{print $1}' fileB | join fileA -






        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited 50 mins ago

























        answered Apr 12 '18 at 0:47









        Jeff SchallerJeff Schaller

        50.3k11 gold badges74 silver badges167 bronze badges




        50.3k11 gold badges74 silver badges167 bronze badges




























            0


















            If the two files are sorted, you can use comm like this to display the lines from fileA that are not in fileB:



            comm -23 fileA fileB


            Or did you also want the lines in fileB that are not in fileA?






            share|improve this answer






















            • 1





              Nope, comm works with whole lines, the OP wants to compare only the first column.

              – Satō Katsura
              Aug 4 '16 at 15:44











            • yes, that is right. thank you nevertheless

              – cloudy_fog
              Aug 4 '16 at 15:45











            • @Sato there's nothing in the question that refers to fields. Everything there says lines.

              – roaima
              Aug 4 '16 at 15:48






            • 1





              join works works with fields.

              – Satō Katsura
              Aug 4 '16 at 15:50
















            0


















            If the two files are sorted, you can use comm like this to display the lines from fileA that are not in fileB:



            comm -23 fileA fileB


            Or did you also want the lines in fileB that are not in fileA?






            share|improve this answer






















            • 1





              Nope, comm works with whole lines, the OP wants to compare only the first column.

              – Satō Katsura
              Aug 4 '16 at 15:44











            • yes, that is right. thank you nevertheless

              – cloudy_fog
              Aug 4 '16 at 15:45











            • @Sato there's nothing in the question that refers to fields. Everything there says lines.

              – roaima
              Aug 4 '16 at 15:48






            • 1





              join works works with fields.

              – Satō Katsura
              Aug 4 '16 at 15:50














            0














            0










            0









            If the two files are sorted, you can use comm like this to display the lines from fileA that are not in fileB:



            comm -23 fileA fileB


            Or did you also want the lines in fileB that are not in fileA?






            share|improve this answer














            If the two files are sorted, you can use comm like this to display the lines from fileA that are not in fileB:



            comm -23 fileA fileB


            Or did you also want the lines in fileB that are not in fileA?







            share|improve this answer













            share|improve this answer




            share|improve this answer










            answered Aug 4 '16 at 14:52









            roaimaroaima

            50.8k7 gold badges67 silver badges136 bronze badges




            50.8k7 gold badges67 silver badges136 bronze badges











            • 1





              Nope, comm works with whole lines, the OP wants to compare only the first column.

              – Satō Katsura
              Aug 4 '16 at 15:44











            • yes, that is right. thank you nevertheless

              – cloudy_fog
              Aug 4 '16 at 15:45











            • @Sato there's nothing in the question that refers to fields. Everything there says lines.

              – roaima
              Aug 4 '16 at 15:48






            • 1





              join works works with fields.

              – Satō Katsura
              Aug 4 '16 at 15:50














            • 1





              Nope, comm works with whole lines, the OP wants to compare only the first column.

              – Satō Katsura
              Aug 4 '16 at 15:44











            • yes, that is right. thank you nevertheless

              – cloudy_fog
              Aug 4 '16 at 15:45











            • @Sato there's nothing in the question that refers to fields. Everything there says lines.

              – roaima
              Aug 4 '16 at 15:48






            • 1





              join works works with fields.

              – Satō Katsura
              Aug 4 '16 at 15:50








            1




            1





            Nope, comm works with whole lines, the OP wants to compare only the first column.

            – Satō Katsura
            Aug 4 '16 at 15:44





            Nope, comm works with whole lines, the OP wants to compare only the first column.

            – Satō Katsura
            Aug 4 '16 at 15:44













            yes, that is right. thank you nevertheless

            – cloudy_fog
            Aug 4 '16 at 15:45





            yes, that is right. thank you nevertheless

            – cloudy_fog
            Aug 4 '16 at 15:45













            @Sato there's nothing in the question that refers to fields. Everything there says lines.

            – roaima
            Aug 4 '16 at 15:48





            @Sato there's nothing in the question that refers to fields. Everything there says lines.

            – roaima
            Aug 4 '16 at 15:48




            1




            1





            join works works with fields.

            – Satō Katsura
            Aug 4 '16 at 15:50





            join works works with fields.

            – Satō Katsura
            Aug 4 '16 at 15:50



















            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f301279%2fopposite-of-join-v%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

            Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

            The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

            Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...