Print only what is exclusive to a file compared to another in Bash

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Good day everyone,



I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.



I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.



File A (1111.com,1112.com,www.1113.com,1114.com)



File B (1111.com,1199.com,1299.com,www2.1329.com)



My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.



Does anyone have a solution ?







share|improve this question























    up vote
    0
    down vote

    favorite












    Good day everyone,



    I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.



    I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.



    File A (1111.com,1112.com,www.1113.com,1114.com)



    File B (1111.com,1199.com,1299.com,www2.1329.com)



    My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.



    Does anyone have a solution ?







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Good day everyone,



      I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.



      I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.



      File A (1111.com,1112.com,www.1113.com,1114.com)



      File B (1111.com,1199.com,1299.com,www2.1329.com)



      My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.



      Does anyone have a solution ?







      share|improve this question











      Good day everyone,



      I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.



      I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.



      File A (1111.com,1112.com,www.1113.com,1114.com)



      File B (1111.com,1199.com,1299.com,www2.1329.com)



      My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.



      Does anyone have a solution ?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 12 at 12:36









      Alistair Wallace

      204




      204




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Not being able to presort the files isn’t a problem:



          comm -13 <(sort fileA) <(sort fileB)


          This gives



          1199.com
          1299.com
          www2.1329.com


          with your examples, assuming each host is on a separate line. -13 tells comm to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.






          share|improve this answer





















          • I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
            – Alistair Wallace
            Jul 12 at 12: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',
          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%2f454886%2fprint-only-what-is-exclusive-to-a-file-compared-to-another-in-bash%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










          Not being able to presort the files isn’t a problem:



          comm -13 <(sort fileA) <(sort fileB)


          This gives



          1199.com
          1299.com
          www2.1329.com


          with your examples, assuming each host is on a separate line. -13 tells comm to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.






          share|improve this answer





















          • I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
            – Alistair Wallace
            Jul 12 at 12:50














          up vote
          3
          down vote



          accepted










          Not being able to presort the files isn’t a problem:



          comm -13 <(sort fileA) <(sort fileB)


          This gives



          1199.com
          1299.com
          www2.1329.com


          with your examples, assuming each host is on a separate line. -13 tells comm to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.






          share|improve this answer





















          • I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
            – Alistair Wallace
            Jul 12 at 12:50












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          Not being able to presort the files isn’t a problem:



          comm -13 <(sort fileA) <(sort fileB)


          This gives



          1199.com
          1299.com
          www2.1329.com


          with your examples, assuming each host is on a separate line. -13 tells comm to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.






          share|improve this answer













          Not being able to presort the files isn’t a problem:



          comm -13 <(sort fileA) <(sort fileB)


          This gives



          1199.com
          1299.com
          www2.1329.com


          with your examples, assuming each host is on a separate line. -13 tells comm to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jul 12 at 12:42









          Stephen Kitt

          139k22296359




          139k22296359











          • I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
            – Alistair Wallace
            Jul 12 at 12:50
















          • I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
            – Alistair Wallace
            Jul 12 at 12:50















          I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
          – Alistair Wallace
          Jul 12 at 12:50




          I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
          – Alistair Wallace
          Jul 12 at 12:50












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454886%2fprint-only-what-is-exclusive-to-a-file-compared-to-another-in-bash%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?

          Christian Cage

          How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?