in Searcher by (15.1k points) recategorized by
0 like 0 dislike
391 views

How I can to do full-text search with help grep Unix utility for whole word only? I.e., how I can to use grep Unix utility/command for only whole word full-text search?

Suitable search queries for this question
  • grep search whole word only
  • how to grep for whole word only
  • whole word only in grep

1 Answer

0 like 0 dislike
by (15.1k points)

There are 2 ways to find whole words with help grep utility:

  1. -w option
  2. \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"

Please log in or register to answer this question.