grep is used to search within a file to see if any line matches a given regular expression. However, I have this situation - I want to write a regular expression that will match the filename itself (and not the contents of the file). I will run this from the system's root directory, to find all those files that match the regular expression.
For example, if I want to find all VB form files that start with an "f" and end with .frm, I'll use the regular expression -
"f[[:alnum:]]*\.frm"
Can grep do this? If not, is there a utility that would let me do this? Thanks.
You need to use find
instead of grep
in this case.
You can also use find
in combination with grep
or egrep
:
$ find | grep "f[[:alnum:]]\.frm"