How the AWK works when 2 files are interchanged in a script while comparing

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-2
down vote

favorite












In the below awk script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case



File 1:



abc bca cdb

abc few bre

bbc bba cdb

cbc frw bte


File 2:



abc bca cdb

gbc fiw bpe

bbc bca cdb

cbc frw bte


Script :



awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**


Output :



gbc fiw bpe

bbc bca cdb


Script:



awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**


Output:



abc few bre

bbc bba cdb






share|improve this question



























    up vote
    -2
    down vote

    favorite












    In the below awk script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case



    File 1:



    abc bca cdb

    abc few bre

    bbc bba cdb

    cbc frw bte


    File 2:



    abc bca cdb

    gbc fiw bpe

    bbc bca cdb

    cbc frw bte


    Script :



    awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**


    Output :



    gbc fiw bpe

    bbc bca cdb


    Script:



    awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**


    Output:



    abc few bre

    bbc bba cdb






    share|improve this question























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      In the below awk script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case



      File 1:



      abc bca cdb

      abc few bre

      bbc bba cdb

      cbc frw bte


      File 2:



      abc bca cdb

      gbc fiw bpe

      bbc bca cdb

      cbc frw bte


      Script :



      awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**


      Output :



      gbc fiw bpe

      bbc bca cdb


      Script:



      awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**


      Output:



      abc few bre

      bbc bba cdb






      share|improve this question













      In the below awk script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case



      File 1:



      abc bca cdb

      abc few bre

      bbc bba cdb

      cbc frw bte


      File 2:



      abc bca cdb

      gbc fiw bpe

      bbc bca cdb

      cbc frw bte


      Script :



      awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**


      Output :



      gbc fiw bpe

      bbc bca cdb


      Script:



      awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**


      Output:



      abc few bre

      bbc bba cdb








      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 18 at 14:26









      Jesse_b

      10.1k22658




      10.1k22658









      asked Jul 18 at 13:14









      Varun Gowda

      33




      33




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          The first command gives you the lines in file2 that can't be found in file1 while the second command gives you the lines in file1 that can't be found in file2.



          For the given data, the code is equivalent to



          awk 'FNR==NR a[$0]++; next !($0 in a)'


          where a is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".






          share|improve this answer





















          • Thanks for the info...
            – Varun Gowda
            Jul 18 at 17:42










          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%2f456990%2fhow-the-awk-works-when-2-files-are-interchanged-in-a-script-while-comparing%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
          0
          down vote



          accepted










          The first command gives you the lines in file2 that can't be found in file1 while the second command gives you the lines in file1 that can't be found in file2.



          For the given data, the code is equivalent to



          awk 'FNR==NR a[$0]++; next !($0 in a)'


          where a is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".






          share|improve this answer





















          • Thanks for the info...
            – Varun Gowda
            Jul 18 at 17:42














          up vote
          0
          down vote



          accepted










          The first command gives you the lines in file2 that can't be found in file1 while the second command gives you the lines in file1 that can't be found in file2.



          For the given data, the code is equivalent to



          awk 'FNR==NR a[$0]++; next !($0 in a)'


          where a is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".






          share|improve this answer





















          • Thanks for the info...
            – Varun Gowda
            Jul 18 at 17:42












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          The first command gives you the lines in file2 that can't be found in file1 while the second command gives you the lines in file1 that can't be found in file2.



          For the given data, the code is equivalent to



          awk 'FNR==NR a[$0]++; next !($0 in a)'


          where a is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".






          share|improve this answer













          The first command gives you the lines in file2 that can't be found in file1 while the second command gives you the lines in file1 that can't be found in file2.



          For the given data, the code is equivalent to



          awk 'FNR==NR a[$0]++; next !($0 in a)'


          where a is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jul 18 at 15:02









          Kusalananda

          101k13199312




          101k13199312











          • Thanks for the info...
            – Varun Gowda
            Jul 18 at 17:42
















          • Thanks for the info...
            – Varun Gowda
            Jul 18 at 17:42















          Thanks for the info...
          – Varun Gowda
          Jul 18 at 17:42




          Thanks for the info...
          – Varun Gowda
          Jul 18 at 17:42












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f456990%2fhow-the-awk-works-when-2-files-are-interchanged-in-a-script-while-comparing%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?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay