nawk - Unable to use 2 variables for NR range

Hi,
I need to break an input file into multiple output files. The number of output files is decided by a maximum record count allowed for each file.

Hence I am using the nawk command to recursively retrieve a range of lines from an input file and write them to output files. But I am unable to use variables for the range to be provided against NR.

cat file.input.XYZ.dat | nawk -F\n '(NR>0 && NR<=10) {print $0}' | tee -a result_tmp.txt

The above works but I need to use $LOWER_LIMIT and $UPPER_LIMIT in the places of 0 and 10.

Please suggest.

# LOWER_LIMIT=10
# UPPER_LIMIT=15
# awk 'NR>x && NR<y' x=$LOWER_LIMIT y=$UPPER_LIMIT in.file

Did you mean to try as following?

cat file.input.XYZ.dat | awk 'NR>x && NR<y' x=$LOWER_LIMIT y=$UPPER_LIMIT result.txt

This only writes the first line in the input file to the output file with the following values.

LOWER_LIMIT=5
UPPER_LIMIT=10

Any other suggestions?

why are you 'cat'-ing something into awk AND also using 'result.txt' as awk's input?

nawk 'NR>x && NR<y' x=$LOWER_LIMIT y=$UPPER_LIMIT  file.input.XYZ.dat