If your grep can read patterns from a file (like GNU grep), try something like this.
Code:
cut -c1-5 file2 >patterns
grep -f patterns file1 >matches
grep -f patterns -v file1 >nonmatches
There is some room for improvement, relating to making the patterns always match at beginning of line, etc. You could replace the first line with something like
Code:
sed 's/^\(.....\).*/^"\1",/' file2 >patterns
This adds the double quotes around the search string and adds a comma behind it and the special character "^" before it, which means match only at beginning of line.