I am grepping the output of a command and I wish to only return specific, strict results.

I remember some iteration of grep had a strict option -s/--strict.

For example, grep -s bytes would only return entries which mentioned the word "bytes" and not every word that contains bytes, like "megabytes", "kilobytes", etc.

   -w, --word-regexp
          Select  only those lines containing matches that form whole
          words.  The test is that the matching
          substring must either be at the beginning of the line, or 
          preceded  by  a  non-word  constituent
          character.   Similarly,  it  must be either at the end of the
          line or followed by a non-word con-
          stituent character.  Word-constituent characters are
          letters, digits, and the underscore.
  • Fantastic, sir. I salute you and your thorough grep knowledge. :) – Nathan Milford May 19 '09 at 15:59
  • 8
    yes, my ability to run "man grep" and search for "word" is, indeed, the stuff of legend =) – jj33 May 19 '09 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.