Here's a DFSORT job that will do what I think you want. I assumed that other records besides the detail records might have '5' in position 9, and what you really want is to truncate the records between but not including the 0s and 9s records.
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file (FB/35)
//SORTOUT DD DSN=... output file (FB/35)
//SYSIN DD *
For your input record example, the output records would be:
If that's NOT what you want, then explain how it differs from what you do want.