How to search words from a column of one file in another file and print matching lines?

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











up vote
0
down vote

favorite












I have two files. For example below:



File 1:



Polaromonas naphthalenivorans
uncultured bacterium
Leptothrix cholodnii
Clostridium clariflavum
Methylocystis parvus
Calditerrivibrio nitroreducens


File 2:



Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
Met parvus 1603 131 0 0 0 197
Caldi nit 998 831 11 70 7 117


Desired output:



Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2






share|improve this question


























    up vote
    0
    down vote

    favorite












    I have two files. For example below:



    File 1:



    Polaromonas naphthalenivorans
    uncultured bacterium
    Leptothrix cholodnii
    Clostridium clariflavum
    Methylocystis parvus
    Calditerrivibrio nitroreducens


    File 2:



    Polaromonas naphthalenivorans 143990 0 6 4 0 0
    uncultured bacterium 43393 0 11174 285 0 0
    Leptothrix cholodnii 26955 0 0 0 0 0
    Clostridium clariflavum 2544 0 3 0 0 2
    Met parvus 1603 131 0 0 0 197
    Caldi nit 998 831 11 70 7 117


    Desired output:



    Polaromonas naphthalenivorans 143990 0 6 4 0 0
    uncultured bacterium 43393 0 11174 285 0 0
    Leptothrix cholodnii 26955 0 0 0 0 0
    Clostridium clariflavum 2544 0 3 0 0 2






    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have two files. For example below:



      File 1:



      Polaromonas naphthalenivorans
      uncultured bacterium
      Leptothrix cholodnii
      Clostridium clariflavum
      Methylocystis parvus
      Calditerrivibrio nitroreducens


      File 2:



      Polaromonas naphthalenivorans 143990 0 6 4 0 0
      uncultured bacterium 43393 0 11174 285 0 0
      Leptothrix cholodnii 26955 0 0 0 0 0
      Clostridium clariflavum 2544 0 3 0 0 2
      Met parvus 1603 131 0 0 0 197
      Caldi nit 998 831 11 70 7 117


      Desired output:



      Polaromonas naphthalenivorans 143990 0 6 4 0 0
      uncultured bacterium 43393 0 11174 285 0 0
      Leptothrix cholodnii 26955 0 0 0 0 0
      Clostridium clariflavum 2544 0 3 0 0 2






      share|improve this question














      I have two files. For example below:



      File 1:



      Polaromonas naphthalenivorans
      uncultured bacterium
      Leptothrix cholodnii
      Clostridium clariflavum
      Methylocystis parvus
      Calditerrivibrio nitroreducens


      File 2:



      Polaromonas naphthalenivorans 143990 0 6 4 0 0
      uncultured bacterium 43393 0 11174 285 0 0
      Leptothrix cholodnii 26955 0 0 0 0 0
      Clostridium clariflavum 2544 0 3 0 0 2
      Met parvus 1603 131 0 0 0 197
      Caldi nit 998 831 11 70 7 117


      Desired output:



      Polaromonas naphthalenivorans 143990 0 6 4 0 0
      uncultured bacterium 43393 0 11174 285 0 0
      Leptothrix cholodnii 26955 0 0 0 0 0
      Clostridium clariflavum 2544 0 3 0 0 2








      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 18:20









      don_crissti

      46.4k15123153




      46.4k15123153










      asked Mar 22 at 18:02









      Manoj Kumar

      12




      12




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          grep has this functionality built-in:



          grep -Ff file1 file2


          means: look for the Fixed strings from file1 in file2 and report the matching lines from file2.






          share|improve this answer




















          • I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
            – Manoj Kumar
            Mar 22 at 18:19











          • then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
            – Jeff Schaller
            Mar 22 at 18:21






          • 1




            @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
            – JJoao
            Mar 22 at 18:34










          • or grep -q $'x0D' file1.csv && echo carriage returns detected
            – Jeff Schaller
            Mar 22 at 18:41










          • File 1 has one column and need to find matching words from file 2.
            – Manoj Kumar
            Mar 22 at 18:41










          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%2f432890%2fhow-to-search-words-from-a-column-of-one-file-in-another-file-and-print-matching%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













          grep has this functionality built-in:



          grep -Ff file1 file2


          means: look for the Fixed strings from file1 in file2 and report the matching lines from file2.






          share|improve this answer




















          • I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
            – Manoj Kumar
            Mar 22 at 18:19











          • then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
            – Jeff Schaller
            Mar 22 at 18:21






          • 1




            @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
            – JJoao
            Mar 22 at 18:34










          • or grep -q $'x0D' file1.csv && echo carriage returns detected
            – Jeff Schaller
            Mar 22 at 18:41










          • File 1 has one column and need to find matching words from file 2.
            – Manoj Kumar
            Mar 22 at 18:41














          up vote
          0
          down vote













          grep has this functionality built-in:



          grep -Ff file1 file2


          means: look for the Fixed strings from file1 in file2 and report the matching lines from file2.






          share|improve this answer




















          • I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
            – Manoj Kumar
            Mar 22 at 18:19











          • then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
            – Jeff Schaller
            Mar 22 at 18:21






          • 1




            @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
            – JJoao
            Mar 22 at 18:34










          • or grep -q $'x0D' file1.csv && echo carriage returns detected
            – Jeff Schaller
            Mar 22 at 18:41










          • File 1 has one column and need to find matching words from file 2.
            – Manoj Kumar
            Mar 22 at 18:41












          up vote
          0
          down vote










          up vote
          0
          down vote









          grep has this functionality built-in:



          grep -Ff file1 file2


          means: look for the Fixed strings from file1 in file2 and report the matching lines from file2.






          share|improve this answer












          grep has this functionality built-in:



          grep -Ff file1 file2


          means: look for the Fixed strings from file1 in file2 and report the matching lines from file2.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 18:15









          Jeff Schaller

          31.2k846105




          31.2k846105











          • I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
            – Manoj Kumar
            Mar 22 at 18:19











          • then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
            – Jeff Schaller
            Mar 22 at 18:21






          • 1




            @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
            – JJoao
            Mar 22 at 18:34










          • or grep -q $'x0D' file1.csv && echo carriage returns detected
            – Jeff Schaller
            Mar 22 at 18:41










          • File 1 has one column and need to find matching words from file 2.
            – Manoj Kumar
            Mar 22 at 18:41
















          • I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
            – Manoj Kumar
            Mar 22 at 18:19











          • then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
            – Jeff Schaller
            Mar 22 at 18:21






          • 1




            @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
            – JJoao
            Mar 22 at 18:34










          • or grep -q $'x0D' file1.csv && echo carriage returns detected
            – Jeff Schaller
            Mar 22 at 18:41










          • File 1 has one column and need to find matching words from file 2.
            – Manoj Kumar
            Mar 22 at 18:41















          I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
          – Manoj Kumar
          Mar 22 at 18:19





          I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
          – Manoj Kumar
          Mar 22 at 18:19













          then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
          – Jeff Schaller
          Mar 22 at 18:21




          then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
          – Jeff Schaller
          Mar 22 at 18:21




          1




          1




          @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
          – JJoao
          Mar 22 at 18:34




          @JeffSchaller and Manoj Kumar, I smell a windows file1 with extra r. What is the file -i ?
          – JJoao
          Mar 22 at 18:34












          or grep -q $'x0D' file1.csv && echo carriage returns detected
          – Jeff Schaller
          Mar 22 at 18:41




          or grep -q $'x0D' file1.csv && echo carriage returns detected
          – Jeff Schaller
          Mar 22 at 18:41












          File 1 has one column and need to find matching words from file 2.
          – Manoj Kumar
          Mar 22 at 18:41




          File 1 has one column and need to find matching words from file 2.
          – Manoj Kumar
          Mar 22 at 18:41












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432890%2fhow-to-search-words-from-a-column-of-one-file-in-another-file-and-print-matching%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