grep regex, match exact string which includes "/" anywhere on line.

I have a file that contains the 2 following lines (from /proc/mounts)

/dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0

I need to match the string in the second column exactly so that only one result is returned, e.g.

> grep "/mnt/backup" /proc/mounts
/dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0
>

This is no good as it returns both lines.

> grep  "\<backup\>" /proc/mounts
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0
>

Works better as it only matches the exact string "backup" (excluding backup2). But I want to match only the entire string "/mnt/backup", but it appears the forward slashes affect the regex and I cannot figure out how to get them interpreted correctly. I have tried escaping them using \ but this does not work.

> grep  "\</mnt/backup\>" /proc/mounts
>
> grep  "\<\/mnt\/backup\>" /proc/mounts
>

I have tried all sorts of other options which would just create noise in the thread and therefore are ommited...

Thanks

grep -w "/mnt/backup" /proc/mounts
1 Like

:o, haha so simple. I did read the man page but obviously not thoroughly enough.

Thanks for that.