Careful here, grep
uses regular expressions
for it's pattern matching, not globbing (a.k.a. wildcards)!
In regex '*
' means 'zero or more of the preceding character
', so 'S_DOC_*
' will match the text string 'S_DOC
', followed by zero or more underscore characters, and only underscores (with no regard to what comes after that--see below)
If you want to match any number of any kind of characters after the explicit text, you need to use the '.
' regex, which means any character
, in front of the asterix: i.e. 'S_DOC_.*
Another difference between globbing and regex though is that globbing patterns must be composed to match the entire
string, but regex only needs to match the desired substring. "S_DOC_
" is therefore the same as ".*S_DOC_.*
" (or the '*S_DOC_*
' gobbing pattern), and will match that pattern anywhere in the line.
Finally, however, to make sure the regex only matches the string at the beginning of the file, you need to anchor
it with the '^
' character (which means "start of line
"). The "^S_DOC_
" regex is equivalent to the "S_DOC_*
" globbing pattern, and probably what you want to use here.
I highly recommend taking some time to learn at least the basics of regex. You won't regret it.
Here are a few regular expressions tutorials: