There are 2 ways to find whole words with help grep
utility:
- -w option
\b
word boundaries in match pattern
Use -w option to specify that it's whole word:
grep -w "str"
Use \b
to match on "word boundaries", which will make your search match on whole words only:
grep "\bSTR\b"
Adding additional options might help too by adding color, line numbers, recursive search and other features:
grep -binrw "str"
grep -binr "\bSTR\b"