don't know how to implentment as unix sh script

for each file if file name like xx*
for each line in a file
if substring(3,6) found in another txt file[ the file just have 1 column but have multiple line]
output to file-a( filename = orginal file + _a)
else
output to file-b( filename = orginal file + _a)
end
Next Line

Assuming you can use bash

See here for how to loop

See here for substring manipulations

use ">>" or ">" to output to file

I am new for sh script , i have write some code but cann't compile , please help for seeing what problem? It seem to cannot read another file in awk and I don't confirm....

"XXXX.wip.sh" 24 lines, 471 characters
>findcust.wip.sh
Syntax Error The source line is 7.
The error context is
while >>> read <<< line
awk: 0602-502 The statement cannot be correctly parsed. The source line is 7.
Syntax Error The source line is 8.

awk -v '
BEGIN {FOUND = "N";}

    \{if \(match\($0, /\\!\\$....../\)\)
            \{checkno = substr\($0,3,6\);
             FOUNDINCUST = "N" ;
             while read line
             do
                    \{if \(FOUNDINCUST="N"\) && \(checkno == $line\)
                            FOUND = "Y";
                            FOUNDINCUST ="Y";
                            print $0 ;
                    \}
             done &lt; "custfilelist.dat" ;
            \}
    \}
    \{if \(match\($0, "%%RECORDEND"\)\)
            FOUND = "N";\}
    \{if \(FOUND =="Y"\)
            print $0 &gt;&gt; "atest.dat" ;\}
    \{if \(FOUND =="N"\)
            print $0 &gt;&gt; "btest.dat" ;\}

' $SOURCEFILE/TEST*.dat

You're mixing awk with sh.

thanks for your reply , it means that I cann't have sh script inside the awk call ? then what should I do to do the objective , should i just use the sh script , not use the awk to do it , any code sample that is doing similar things ??