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.
pattern1, pattern2form 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
My initial attempt was
awk '/select/,/from/' *
* 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 '/[^<]select[^>]/,/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?