in Searcher by (14.2k points) recategorized by
0 like 0 dislike
31 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 (14.2k 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"

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.