Grep word matching
Clash 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
grep
add a comment |Â
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
grep
add a comment |Â
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
grep
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
grep
edited Dec 7 '17 at 10:18
Jeff Schaller
32k848109
32k848109
asked Dec 7 '17 at 9:16
again
1237
1237
add a comment |Â
add a comment |Â
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$"
add a comment |Â
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$"
add a comment |Â
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$"
add a comment |Â
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$"
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$"
answered Dec 7 '17 at 9:22
Murphy
1,7471517
1,7471517
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password