ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded.
It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used.
ie, scan lines 45 - 20000 first pass. second pass, scan lines 104-1065,third pass scan 742-5954...

The script returns some maths: (max, min, and ::: not yet there: line numbers of max, min, block average). There are ~10,000 files to examine. would like to pass this back into an array or list variable

the $item file looks like this:
123456788,-111.2316547
123456789,-25.1234579
...

Problem: it needs to search run-time defined blocks of the file, ie, between lines r and j. I can't quite get this part to work:

it uses -v to capture the variables: awk -v rstart=$r -v jend
and tries to block it off this way: if ((NR >= $rstart) && (NR <= $jend)

Good news, the awk works if you: if ((NR >= 45) && (NR <= 1000))

Secondary issue: have the results populate an array or list that i can work with later in ksh.

function return_minmax_r_j
 {
 awk -v rstart=$r -v jend=$j 'function  max(x){i=-999;for(val in x){if(i<=x[val]){i=x[val];}}return  i;}function min(x){i=max(x);for(val in  x){if(i>x[val]){i=x[val];}}return i;}{FS=","}{if ((NR >= $rstart)  && (NR <= $jend))  a[$2]=$2;next}END{minimum=min(a);maximum=max(a);  print maximum minimum}' $item 
 }
#===MAIN===
 generate_file_name_array  #generates a list of file names

 for item in ${FILE_LIST_ARRAY[@]} 
                do 
                r=45
                j=2000  #these will be variables declared later.

                return_minmax_r_j
                done
 return
  • In awk, variable references are without $-signs... for example:
if ((NR >= rstart) && (NR <= jend)
  • When assigning shell variables to awk variable, it is good practice to quote the shell variables, since it is not a shell assignment:
awk -v rstart="$r" ...