validating data

I have a file like the following

  aaaaa00005bbbbb
  aaaaa00108bbbbb

The code "00005" and "00108" need to be validated and the list of valid codes are stored in a database.

While I loop through the file, should call a sql statement for every records to do the validation? or is there a better way to do it?

Thanks in advance.

It depends on whether you want to say this whole file is okay, use it, or if you want a line is okay use it or line is okay pitch it.

For the latter, your idea is fine, for the former try:

tr -d [[:alpha:]] < filename | sort -u >testfile

Then feed testfile to a validation routine.