I am trying to use the awk range pattern to find all SQL select statements in a group of files, inspired by this stackoverflow answer.

From the awk manual:


  The pattern1, pattern2 form of an expression is called a range pattern.  It matches all input records starting with a record that matches pattern1, and continuing until a record that matches  pattern2,  inclusive.


My initial attempt was 

awk '/select/,/from/' *


where * in this case just represents a large number of varied files.

This returned several false hits on HTML select tags, so I refined my command to

awk '/[^&lt;]select[^&gt;]/,/from/' *


which seems to have eliminated most of those hits.

However, I still get some false hits from occurrences of the word "select" in a comment, and those hits produce very many lines of noise each before they eventually hit a "from" or the end of the file.
What I would like is for the range pattern not to register a match if there are more than, say, 10 lines between the "select" and the "from".

My question is: Can I make the range pattern fail to match if the number of lines between the match of pattern1 and the match of pattern2 exceeds a given threshold, and if so, how?


Question: Why does hand sanitizer leave your skin feeling cool?
Answer: Hand sanitizer leaves your hands feeling cool because the particles in the gel which posses the most amount of energy are able to evaporate from the gel and off your hands. This results in only the particles with low energy levels to be left on your hand which therefore reduces the hands overall temperature.