I'm trying to figure out how to use grep
to search for for a specific string, (for the sake of simplicity) say "9"
, and I want to search for this, again for simplicity, on all files containing the character b
.
I tried grep -e "9" b
, but it says it can't find file b
. (The same if I don't use the -e
option).
I know that I could go for grep -e "9" *b*
, but that's not my point. I want the usual tools of regular expressions to use for filename matching.
I'm not interested in convoluted ways of obtaining this. I'm hoping there is a simple option in grep
that I can use for this. I perused the man
and I can't find anything useful, but I'm pretty new to shell scripting, so I could very easily be missing it.
Is it possible to use regular expression for filename matching using just grep
? If so, how?
grep -e "9" *b*
you use usual regex to match filename (and content of the file) – Romeo Ninov Dec 24 '18 at 16:48grep -e "9" *b*
, but that's not my point". I have no reason to believe this is anything other than simply using the wildcard*
. I'm asking about being able to use the whole typical regexs tool belt. For instancegrep -e "9" ^b*
doesn't work. – newbie Dec 24 '18 at 16:51grep
implementation, you may be able to use its--include
and/or--exclude
options - however these use glob matching, rather than regular expressions – steeldriver Dec 24 '18 at 16:53ls
(for example) and you can have the full spread of regex – Romeo Ninov Dec 24 '18 at 16:53