To search for a string as a whole word only in grep, which option is used?

Disable ads (and more) with a premium pass for a one time $4.99 payment

Boost your Linux skills with the CompTIA Linux+ Certification Exam simulator. Engage with multiple choice questions and detailed feedback. Master Linux concepts and prepare for your exam with confidence!

The option used to search for a string as a whole word only in the grep command is indeed the one that specifies boundaries for matching. When using this option, grep will only return lines where the specified string appears as a complete word, rather than as part of another word or string.

For example, searching for "cat" with this option will match "cat" but not "catalog" or "scattered." This is particularly useful in situations where you want to filter out partial matches and focus on exact occurrences of a word within text files, thus ensuring accuracy in your search results.

The other options serve different purposes:

  • The option that specifies line numbers will add the line numbers to the output, but does not enforce whole word matching.
  • The option that matches entire lines restricts matches to those that consist entirely of the desired string, which is more stringent than whole word matching.
  • The option that allows for multiple patterns does not specifically filter for full-word instances and is designed to facilitate searching for multiple strings at once.

Thus, the correct option focuses solely on whole word matches, making it the appropriate choice for such a search requirement.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy