1

I'm trying to grep some code for any code that matches 'enforce' and the following works and shows results:

grep --include=\*.rb -rnw . -e enforce

yet the following gives no results:

grep --include=\*.rb -rnw . -e enforc

How do I grep for anything that contains 'enforc'?

25

Remove w from the options:

grep --include=\*.rb -rn . -e enforc

-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 constituent character. Word-constituent characters are letters, digits, and the underscore.

  • Oh thanks, that was stupid of me, I just copied code without looking at what it did. – simonzack May 7 at 8:39
  • 4
    @simonzack Any time you see -blahblah that means it's doing something (and, furthermore, something that isn't the default) so, yeah, that's the first thing to check. – David Richerby May 7 at 12:25

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.