I am using grep from Gnuwin32 on Windows.
Doing:
grep -r INSERT *.sql
Yields:
grep: *.sql: Invalid argument
Any idea why?
According to the Grep manual:
-r with grep is recursive directory searching, so to use it you specify the starting directory, not a file mask.
e.g.:
grep -r INSERT . would look at all files for INSERT, starting at the current directory (.) and recursively working its way through the sub-folders.
To specify recursive folder checking and specify a file wildcard to limit searches, you can use the --include option:
grep -r --include "*.sql" INSERT .
Similar question/info over on StackOverflow: How do I grep recursively?
grep is a great tool with some interesting parameters. However, as its name says (globally search a regular expression and print) it is meant for matching things. If what you want is to find files, use find.
In this case, it looks like you want to look for the text INSERT within files that are in this tree.
For this, you need to do something like:
find -name "*.sql" grep -h INSERT {} \;
find -name "*.sql" will find all these files and then grep -h will print those having the text INSERT in them.
Why wasn't your approach working?
Because by saying grep -r ... *.sql, bash tries to expand that *.sql before performing the command. But nothing matches *.sql in your directory, so it cannot work.
You can use the --include parameter with a regexp, but -in my experience- it is quite fragile.