Testing Fgrep Gives Same Results As Grep












0















I'm trying to learn how fgrep differs from grep. However in my test results, there is no difference. Apparently fgrep matches on strings and ignores regex. So I put this to the test and there was absolutely nothing that a basic fgrep can do, that grep can't. So I can't move on, I need to understand why I have the results below, and what the difference between fgrep is, since I categorically cannot see any difference in any test result.



$ cat testfile
subscribe|unsubscribe
@lp1n3

$ grep 'subscribe|unsubscribe' testfile
subscribe|unsubscribe
$ fgrep 'subscribe|unsubscribe' testfile
subscribe|unsubscribe

$ grep '@lp1n3' testfile
@lp1n3
$ fgrep '@lp1n3' testfile
@lp1n3









share|improve this question



























    0















    I'm trying to learn how fgrep differs from grep. However in my test results, there is no difference. Apparently fgrep matches on strings and ignores regex. So I put this to the test and there was absolutely nothing that a basic fgrep can do, that grep can't. So I can't move on, I need to understand why I have the results below, and what the difference between fgrep is, since I categorically cannot see any difference in any test result.



    $ cat testfile
    subscribe|unsubscribe
    @lp1n3

    $ grep 'subscribe|unsubscribe' testfile
    subscribe|unsubscribe
    $ fgrep 'subscribe|unsubscribe' testfile
    subscribe|unsubscribe

    $ grep '@lp1n3' testfile
    @lp1n3
    $ fgrep '@lp1n3' testfile
    @lp1n3









    share|improve this question

























      0












      0








      0








      I'm trying to learn how fgrep differs from grep. However in my test results, there is no difference. Apparently fgrep matches on strings and ignores regex. So I put this to the test and there was absolutely nothing that a basic fgrep can do, that grep can't. So I can't move on, I need to understand why I have the results below, and what the difference between fgrep is, since I categorically cannot see any difference in any test result.



      $ cat testfile
      subscribe|unsubscribe
      @lp1n3

      $ grep 'subscribe|unsubscribe' testfile
      subscribe|unsubscribe
      $ fgrep 'subscribe|unsubscribe' testfile
      subscribe|unsubscribe

      $ grep '@lp1n3' testfile
      @lp1n3
      $ fgrep '@lp1n3' testfile
      @lp1n3









      share|improve this question














      I'm trying to learn how fgrep differs from grep. However in my test results, there is no difference. Apparently fgrep matches on strings and ignores regex. So I put this to the test and there was absolutely nothing that a basic fgrep can do, that grep can't. So I can't move on, I need to understand why I have the results below, and what the difference between fgrep is, since I categorically cannot see any difference in any test result.



      $ cat testfile
      subscribe|unsubscribe
      @lp1n3

      $ grep 'subscribe|unsubscribe' testfile
      subscribe|unsubscribe
      $ fgrep 'subscribe|unsubscribe' testfile
      subscribe|unsubscribe

      $ grep '@lp1n3' testfile
      @lp1n3
      $ fgrep '@lp1n3' testfile
      @lp1n3






      grep






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 28 at 13:00









      john smithjohn smith

      1,06542041




      1,06542041






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You may find it helpful to add the -o switch to make it easier to see what's happening:



          $ grep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Here we are using grep in Basic Regular Expression mode, where | is not special (it would need to be escaped | to mean OR), so the pattern is matched as a single string



          $ grep -oE 'subscribe|unsubscribe' testfile
          subscribe
          unsubscribe


          Here we have switched to Extended Regular Expression (ERE) mode, where | is a regex special character, so we are matching two patterns, subscribe and unsubscribe



          $ grep -oF 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Now we are matching in fixed string mode (like fgrep) and as expected | is not special - just like BRE.



          fgrep is an (officially, deprecated) equivalent of grep -F so it behaves exactly the same:



          $ fgrep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          As far as I know, @ isn't special in either BRE or ERE, so will always give the same result as fgrep or grep -F.






          share|improve this answer


























          • Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

            – john smith
            Feb 28 at 13:30











          • @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

            – steeldriver
            Feb 28 at 13:35














          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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/3.0/"u003ecc by-sa 3.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%2faskubuntu.com%2fquestions%2f1121976%2ftesting-fgrep-gives-same-results-as-grep%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You may find it helpful to add the -o switch to make it easier to see what's happening:



          $ grep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Here we are using grep in Basic Regular Expression mode, where | is not special (it would need to be escaped | to mean OR), so the pattern is matched as a single string



          $ grep -oE 'subscribe|unsubscribe' testfile
          subscribe
          unsubscribe


          Here we have switched to Extended Regular Expression (ERE) mode, where | is a regex special character, so we are matching two patterns, subscribe and unsubscribe



          $ grep -oF 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Now we are matching in fixed string mode (like fgrep) and as expected | is not special - just like BRE.



          fgrep is an (officially, deprecated) equivalent of grep -F so it behaves exactly the same:



          $ fgrep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          As far as I know, @ isn't special in either BRE or ERE, so will always give the same result as fgrep or grep -F.






          share|improve this answer


























          • Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

            – john smith
            Feb 28 at 13:30











          • @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

            – steeldriver
            Feb 28 at 13:35


















          0














          You may find it helpful to add the -o switch to make it easier to see what's happening:



          $ grep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Here we are using grep in Basic Regular Expression mode, where | is not special (it would need to be escaped | to mean OR), so the pattern is matched as a single string



          $ grep -oE 'subscribe|unsubscribe' testfile
          subscribe
          unsubscribe


          Here we have switched to Extended Regular Expression (ERE) mode, where | is a regex special character, so we are matching two patterns, subscribe and unsubscribe



          $ grep -oF 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Now we are matching in fixed string mode (like fgrep) and as expected | is not special - just like BRE.



          fgrep is an (officially, deprecated) equivalent of grep -F so it behaves exactly the same:



          $ fgrep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          As far as I know, @ isn't special in either BRE or ERE, so will always give the same result as fgrep or grep -F.






          share|improve this answer


























          • Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

            – john smith
            Feb 28 at 13:30











          • @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

            – steeldriver
            Feb 28 at 13:35
















          0












          0








          0







          You may find it helpful to add the -o switch to make it easier to see what's happening:



          $ grep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Here we are using grep in Basic Regular Expression mode, where | is not special (it would need to be escaped | to mean OR), so the pattern is matched as a single string



          $ grep -oE 'subscribe|unsubscribe' testfile
          subscribe
          unsubscribe


          Here we have switched to Extended Regular Expression (ERE) mode, where | is a regex special character, so we are matching two patterns, subscribe and unsubscribe



          $ grep -oF 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Now we are matching in fixed string mode (like fgrep) and as expected | is not special - just like BRE.



          fgrep is an (officially, deprecated) equivalent of grep -F so it behaves exactly the same:



          $ fgrep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          As far as I know, @ isn't special in either BRE or ERE, so will always give the same result as fgrep or grep -F.






          share|improve this answer















          You may find it helpful to add the -o switch to make it easier to see what's happening:



          $ grep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Here we are using grep in Basic Regular Expression mode, where | is not special (it would need to be escaped | to mean OR), so the pattern is matched as a single string



          $ grep -oE 'subscribe|unsubscribe' testfile
          subscribe
          unsubscribe


          Here we have switched to Extended Regular Expression (ERE) mode, where | is a regex special character, so we are matching two patterns, subscribe and unsubscribe



          $ grep -oF 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          Now we are matching in fixed string mode (like fgrep) and as expected | is not special - just like BRE.



          fgrep is an (officially, deprecated) equivalent of grep -F so it behaves exactly the same:



          $ fgrep -o 'subscribe|unsubscribe' testfile
          subscribe|unsubscribe


          As far as I know, @ isn't special in either BRE or ERE, so will always give the same result as fgrep or grep -F.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 28 at 13:34

























          answered Feb 28 at 13:12









          steeldriversteeldriver

          70.5k11114187




          70.5k11114187













          • Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

            – john smith
            Feb 28 at 13:30











          • @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

            – steeldriver
            Feb 28 at 13:35





















          • Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

            – john smith
            Feb 28 at 13:30











          • @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

            – steeldriver
            Feb 28 at 13:35



















          Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

          – john smith
          Feb 28 at 13:30





          Not sure if I made my question clear. My question is what's the difference between fgrep and grep, because my testing shows that there is no difference.

          – john smith
          Feb 28 at 13:30













          @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

          – steeldriver
          Feb 28 at 13:35







          @johnsmith sorry I should have mentioned - fgrep is equivalent to grep -F (I have edited the answer to make that clearer)

          – steeldriver
          Feb 28 at 13:35




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • 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%2faskubuntu.com%2fquestions%2f1121976%2ftesting-fgrep-gives-same-results-as-grep%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

          flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

          Mangá

          Eduardo VII do Reino Unido