Hard to do since it's not clear what exactly you want.
Please show an example of the records in your input file and what exactly you want for output. Please explain what you're doing, if anything, that would make the output count different than the input count (e.g. INCLUDE?).