Home:ALL Converter>sed: How to find whole word which contains special char "/"?

sed: How to find whole word which contains special char "/"?

Ask Time:2021-09-22T05:57:01         Author:andrew

Json Formatter

I would like to search an exact word which contains the special char / like this word "/var/tmp". I found some example how to search whole word like this sed '/\b$word\b/g' But it works only on standard words, not contains meta. Any idea please?

INPUT>

 word="/var/tmp"
  cat /etc/mtab | grep $word
/dev/mapper/vgroot-lvvar /tmp/var/tmp ext4 rw,seclabel,relatime 0 0
/dev/mapper/vgroot-lv_var_tmp /var/tmp xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
/dev/mapper/vgroot-lv_var_tmp /tmp/var/tmp xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0

OUTPUT is working only with exact example, but not with universal variable $word

cat /etc/mtab | grep $word | sed '/\b\/var\/tmp\b/g'
/dev/mapper/vgroot-lv_var_tmp /var/tmp xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0

Not working output with variable, filter not working here

cat /etc/mtab | grep $word | sed '/\b\$word\b/g'
/dev/mapper/vgroot-lvvar /tmp/var/tmp ext4 rw,seclabel,relatime 0 0
/dev/mapper/vgroot-lv_var_tmp /var/tmp xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
/dev/mapper/vgroot-lv_var_tmp /tmp/var/tmp xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0

Author:andrew,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275967/sed-how-to-find-whole-word-which-contains-special-char
yy