Grep word matching

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











up vote
-2
down vote

favorite












This is strange. I want only to grep line containing /run. But it returning other lines too.



 [root@s5 ~]# df -h | grep -w "tm"
[root@s5 ~]# df -h | grep -w "tmpfs"
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.8M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
tmpfs 98M 0 98M 0% /run/user/1001
tmpfs 98M 0 98M 0% /run/user/0
[root@s5 ~]# df -h | grep -w "tmpf"
[root@s5 ~]# df -h | grep -w "/run"
tmpfs 489M 6.8M 483M 2% /run
tmpfs 98M 0 98M 0% /run/user/1001
tmpfs 98M 0 98M 0% /run/user/0






share|improve this question


























    up vote
    -2
    down vote

    favorite












    This is strange. I want only to grep line containing /run. But it returning other lines too.



     [root@s5 ~]# df -h | grep -w "tm"
    [root@s5 ~]# df -h | grep -w "tmpfs"
    tmpfs 489M 0 489M 0% /dev/shm
    tmpfs 489M 6.8M 483M 2% /run
    tmpfs 489M 0 489M 0% /sys/fs/cgroup
    tmpfs 98M 0 98M 0% /run/user/1001
    tmpfs 98M 0 98M 0% /run/user/0
    [root@s5 ~]# df -h | grep -w "tmpf"
    [root@s5 ~]# df -h | grep -w "/run"
    tmpfs 489M 6.8M 483M 2% /run
    tmpfs 98M 0 98M 0% /run/user/1001
    tmpfs 98M 0 98M 0% /run/user/0






    share|improve this question
























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      This is strange. I want only to grep line containing /run. But it returning other lines too.



       [root@s5 ~]# df -h | grep -w "tm"
      [root@s5 ~]# df -h | grep -w "tmpfs"
      tmpfs 489M 0 489M 0% /dev/shm
      tmpfs 489M 6.8M 483M 2% /run
      tmpfs 489M 0 489M 0% /sys/fs/cgroup
      tmpfs 98M 0 98M 0% /run/user/1001
      tmpfs 98M 0 98M 0% /run/user/0
      [root@s5 ~]# df -h | grep -w "tmpf"
      [root@s5 ~]# df -h | grep -w "/run"
      tmpfs 489M 6.8M 483M 2% /run
      tmpfs 98M 0 98M 0% /run/user/1001
      tmpfs 98M 0 98M 0% /run/user/0






      share|improve this question














      This is strange. I want only to grep line containing /run. But it returning other lines too.



       [root@s5 ~]# df -h | grep -w "tm"
      [root@s5 ~]# df -h | grep -w "tmpfs"
      tmpfs 489M 0 489M 0% /dev/shm
      tmpfs 489M 6.8M 483M 2% /run
      tmpfs 489M 0 489M 0% /sys/fs/cgroup
      tmpfs 98M 0 98M 0% /run/user/1001
      tmpfs 98M 0 98M 0% /run/user/0
      [root@s5 ~]# df -h | grep -w "tmpf"
      [root@s5 ~]# df -h | grep -w "/run"
      tmpfs 489M 6.8M 483M 2% /run
      tmpfs 98M 0 98M 0% /run/user/1001
      tmpfs 98M 0 98M 0% /run/user/0








      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 7 '17 at 10:18









      Jeff Schaller

      32k848109




      32k848109










      asked Dec 7 '17 at 9:16









      again

      1237




      1237




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          man grep:




          -w, --word-regexp
          Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.




          Works as expected, I say. If your intention is to get only the first match you should use



          $ df -h | grep -w "/run$"





          share|improve this answer




















            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%2f409428%2fgrep-word-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
            3
            down vote



            accepted










            man grep:




            -w, --word-regexp
            Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.




            Works as expected, I say. If your intention is to get only the first match you should use



            $ df -h | grep -w "/run$"





            share|improve this answer
























              up vote
              3
              down vote



              accepted










              man grep:




              -w, --word-regexp
              Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.




              Works as expected, I say. If your intention is to get only the first match you should use



              $ df -h | grep -w "/run$"





              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                man grep:




                -w, --word-regexp
                Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.




                Works as expected, I say. If your intention is to get only the first match you should use



                $ df -h | grep -w "/run$"





                share|improve this answer












                man grep:




                -w, --word-regexp
                Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.




                Works as expected, I say. If your intention is to get only the first match you should use



                $ df -h | grep -w "/run$"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 7 '17 at 9:22









                Murphy

                1,7471517




                1,7471517



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409428%2fgrep-word-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