Code:
grep -Ri 'accesslevel\s*=\s*3' dirname
My first guess is that you need to quote the pattern.
I'm surprised the first command-line you gave worked, because the spaces aren't quoted. It might work (in the sense of producing output) because everything after the word "accesslevel" is treated as a filename, and if there's no file or dir named "=" or "3", then it's simply skipped.
Quoting the pattern would look like this, for each example you gave:
Code:
grep -Ri 'accesslevel = 3' dirname
grep -Ri 'accesslevel\s*=\s*3' dirname
grep -Ri 'accesslevel?*=?*3' dirname
How to use the CODE tag in posts.
My second guess is that grep doesn't recognize "\s". You should read its man page to make sure, as this might vary depending on OS version (or post 'grep --version'). Also look at the 'egrep' command, and/or the -E option to grep.
For the grep I have here, it DOES NOT recognize "\s" as a meta pattern, which means it's treated as a simple "s" character.
The "*" means "zero or more times" for whatever the prior expression is. So on my machine, that would be "zero ore more S's". This would NOT match any space characters, because space isn't an "s" or "S".
The third command (with ?'s) is unlikely to produce what you want. If you expect "?" to mean "any character", then that's not how grep works. Grep's "any character" meta-character is "." (dot). Conversely, the shell's pattern expansion DOES treat ? as "any single character". Unfortunately, the
shell's patterns are quite different from grep's.
Grep has named classes for a variety of character classes. The name for whitespace is "[:space:]". Since this name is only recognized between []'s, the pattern is "[[:space:]]". So the sub-pattern that means "zero or more whitespace" is:
Code:
grep -Ri 'accesslevel[[:space:]]*=[[:space:]]*3' dirname
"zero or more anything" is:
Code:
grep -Ri 'accesslevel.*=.*3' dirname
And "one or more whitespace" would be:
Code:
grep -Ri 'accesslevel[[:space:]]+=[[:space:]]+3' dirname
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/egrep.1.html
https://developer.apple.com/legacy/...format.7.html#//apple_ref/doc/man/7/re_format