2 Replies Latest reply on Oct 9, 2012 8:39 AM by Dude!

    grep for whole word containing slashes


      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}'
      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?