awk 'NR==FNR{a[substr($0,1,5)];next} NF<3{next} substr($1,2,5) in a {print > "file1";next} {print > "file2"}' file2 file1