Using awk to when reading a file to search and output to file

Hi, I am not sure if this will work or not. I am getting a syntax error.

I am reading fileA, using an acct number field trying to see if it exists in fileB and output to new file. Can anyone tell me if what I am doing will work or should I attempt it another way? Thanks.

 
exec < "${fileA}
while read dataline
do
ACCT=`echo "${dataline}" | cut -c 1-7`
 
awk `{print substr($0,11,7)=="${ACCT}"}` "${fileB}" >> "${fileC}"

I am a syntax error on the awk line. Thanks in advance for your help.

awk 'substr($0,11,7)== "'"${ACCT}"'" {print }' "${fileB}" >> "${fileC}"

Thanks, I'll try it right now.

---------- Post updated at 12:52 PM ---------- Previous update was at 12:42 PM ----------

It didn't work but did get further. I have an eof unexpected issue but no file created.

I think you need this:

awk 'NR==FNR{f[substr($0,1,7)];next}substr($0,11,7) in f{print $0>"file3"}' file1 file2

anbu23, Thanks so much. It worked perfectly. The problem was PEBCAC.

---------- Post updated at 01:12 PM ---------- Previous update was at 01:10 PM ----------

kcoder24. I just saw your response. Thanks also for responding. But it looks like I'm good now. You guys are great!