Awk error -- awk: 0602-562 Field $() is not correct.

typeset -i i=1
while read -r filename; do

Splitfile=`$Targetfile_$i.txt`
awk 'substr($0,1,5) == substr($filename,1,5) && substr($0,526,2) == substr($filename,6,2) && substr($0,750,12) == substr($filename,8,12)' $SourceFilename >> $Splitfile
i=i+1
done < /tmp/list.out

I am using this logic to compare the positions and outputting the file based on that

I am getting the following awk error when executing it

awk: 0602-562 Field $() is not correct.

Help will be appreciated

To use a shell variabele with awk you should do something like this:

awk -v fn="$filename" 'substr($0,1,5) == substr(fn,1,5).....'

Have a read of:

Using Shell Variables - The GNU Awk User's Guide