script problem

Hello

I am trying to execute the following script

#!/bin/ksh
ABC=/abc/def/ghi/jkl/mna/opq/input
cd $ABC
Filename=`ls -t $ABC | tail -1`;
echo $Filename
awk 'NR == 1 || substr($0,63,5) ~ /H... / && \
++ == 1 { fn && close(fn); fn = "$Filename" ++c; _ = 1 }
{ print > fn }' $Filename

i need to split the file based on certain condition. I want the splitted files with the naming convention as of input filename appended by _1,_2.. etc.

When i am trying to execute the above script fn is not getting assigned to input filename and i am getting the file names as below
$Filename_1
$Filename_2.....

Please help me
Thanks

$Filename isn't known within awk. You could do this:
awk 'NR == 1 || substr($0,63,5) ~ /H... / && \
++ == 1 { fn && close(fn); fn = Z "" ++c; _ = 1 }
{ print > fn }' Z=$Filename $Filename

Thanks

That works