UNIX: excluding patterns, contained in a file, from another file with grep

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











up vote
2
down vote

favorite
1












I have a txt file that contains the patterns I would like to exclude from a file. Is there a way to chain grep -f and grep -v?



Thanks







share|improve this question


























    up vote
    2
    down vote

    favorite
    1












    I have a txt file that contains the patterns I would like to exclude from a file. Is there a way to chain grep -f and grep -v?



    Thanks







    share|improve this question
























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I have a txt file that contains the patterns I would like to exclude from a file. Is there a way to chain grep -f and grep -v?



      Thanks







      share|improve this question














      I have a txt file that contains the patterns I would like to exclude from a file. Is there a way to chain grep -f and grep -v?



      Thanks









      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 9 '16 at 21:24









      sam

      12.3k31326




      12.3k31326










      asked Jun 9 '16 at 21:11









      Nicholas Hayden

      355




      355




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          You can use the options together like:



          grep -vf exclude.txt file.txt


          Example:



          $ cat exclude.txt 
          3

          $ cat file.txt
          1
          3
          4
          1
          4
          3
          1
          2

          $ grep -vf exclude.txt file.txt
          1
          4
          1
          4
          1
          2





          share|improve this answer




















          • Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
            – Nicholas Hayden
            Jun 9 '16 at 21:19











          • @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
            – heemayl
            Jun 9 '16 at 21:22







          • 1




            @NicholasHayden, you might want to check out the -x and -F options in man grep.
            – Wildcard
            Jun 9 '16 at 21:39










          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%2f288809%2funix-excluding-patterns-contained-in-a-file-from-another-file-with-grep%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
          4
          down vote













          You can use the options together like:



          grep -vf exclude.txt file.txt


          Example:



          $ cat exclude.txt 
          3

          $ cat file.txt
          1
          3
          4
          1
          4
          3
          1
          2

          $ grep -vf exclude.txt file.txt
          1
          4
          1
          4
          1
          2





          share|improve this answer




















          • Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
            – Nicholas Hayden
            Jun 9 '16 at 21:19











          • @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
            – heemayl
            Jun 9 '16 at 21:22







          • 1




            @NicholasHayden, you might want to check out the -x and -F options in man grep.
            – Wildcard
            Jun 9 '16 at 21:39














          up vote
          4
          down vote













          You can use the options together like:



          grep -vf exclude.txt file.txt


          Example:



          $ cat exclude.txt 
          3

          $ cat file.txt
          1
          3
          4
          1
          4
          3
          1
          2

          $ grep -vf exclude.txt file.txt
          1
          4
          1
          4
          1
          2





          share|improve this answer




















          • Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
            – Nicholas Hayden
            Jun 9 '16 at 21:19











          • @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
            – heemayl
            Jun 9 '16 at 21:22







          • 1




            @NicholasHayden, you might want to check out the -x and -F options in man grep.
            – Wildcard
            Jun 9 '16 at 21:39












          up vote
          4
          down vote










          up vote
          4
          down vote









          You can use the options together like:



          grep -vf exclude.txt file.txt


          Example:



          $ cat exclude.txt 
          3

          $ cat file.txt
          1
          3
          4
          1
          4
          3
          1
          2

          $ grep -vf exclude.txt file.txt
          1
          4
          1
          4
          1
          2





          share|improve this answer












          You can use the options together like:



          grep -vf exclude.txt file.txt


          Example:



          $ cat exclude.txt 
          3

          $ cat file.txt
          1
          3
          4
          1
          4
          3
          1
          2

          $ grep -vf exclude.txt file.txt
          1
          4
          1
          4
          1
          2






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 9 '16 at 21:13









          heemayl

          33.1k36897




          33.1k36897











          • Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
            – Nicholas Hayden
            Jun 9 '16 at 21:19











          • @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
            – heemayl
            Jun 9 '16 at 21:22







          • 1




            @NicholasHayden, you might want to check out the -x and -F options in man grep.
            – Wildcard
            Jun 9 '16 at 21:39
















          • Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
            – Nicholas Hayden
            Jun 9 '16 at 21:19











          • @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
            – heemayl
            Jun 9 '16 at 21:22







          • 1




            @NicholasHayden, you might want to check out the -x and -F options in man grep.
            – Wildcard
            Jun 9 '16 at 21:39















          Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
          – Nicholas Hayden
          Jun 9 '16 at 21:19





          Thanks! However, grep does not seem to filtering based on exclude.txt - Would there be a problem with the exclude.txt?
          – Nicholas Hayden
          Jun 9 '16 at 21:19













          @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
          – heemayl
          Jun 9 '16 at 21:22





          @NicholasHayden Thats the way to go. If you have any problem then it must be with the patterns.
          – heemayl
          Jun 9 '16 at 21:22





          1




          1




          @NicholasHayden, you might want to check out the -x and -F options in man grep.
          – Wildcard
          Jun 9 '16 at 21:39




          @NicholasHayden, you might want to check out the -x and -F options in man grep.
          – Wildcard
          Jun 9 '16 at 21:39

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f288809%2funix-excluding-patterns-contained-in-a-file-from-another-file-with-grep%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