Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

grep for whole word containing slashes

Dude!Oct 8 2012 — edited Oct 9 2012
Hi,

I'm trying to query the output of mount to verify that a given argument is really a btrfs mount point and return the actual device name. For instance:
# mount | grep /mnt/0  | grep btrfs | awk '{print $1}'
/dev/sda3
The above works fine. But fails when the argument is e.g. /mnt, which exists, but is not a mount point. Trying to match the whole word using -w does not work. For instance:
# mount | grep -w /mnt
/dev/sda3 on /mnt/root type btrfs (rw,seclabel,relatime,space_cache)
/dev/sda3 on /mnt/258 type btrfs (rw,seclabel,relatime,space_cache)
/dev/sda3 on /mnt/0 type btrfs (rw,seclabel,relatime,space_cache)
Unfortunately the above returns 3 matches, although /mnt isn't a mount point.

I could use mountpoint and perhaps other methods, but I wonder if there is perhaps just a simple change required to make grep consider the forward slash as part of a word.

Any ideas?

Thanks.
This post has been answered by Nik on Oct 9 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 6 2012
Added on Oct 8 2012
2 comments
734 views