I have a input file in the below format.
-------------------------------------------------------------------------------------

Code:

SQL> SET ECHO OFF
SQL> SET HEADING OFF
SQL> SET TERMOUT OFF
SQL> SET FEEDBACK OFF
SQL> SET TRIMSPOOL ON
SQL> SET PAGESIZE 0
SQL> SET COLSEP ','
SQL> SELECT TZR,PROP_CODE,TO_CHAR(INV_DATE,'YYYY'),'3001',
2 TO_CHAR(INV_DATE,'YYYY-MM-DD'),'0',USER_NOTES
3 FROM OYT_XP_DAILY_SPREAD
4 WHERE INV_DATE BETWEEN TO_DATE('02/01/2018','MM/DD/YYYY')
3,BADPT,2018,3001,2018-02-01,0

The records in INPUT IS IN THE BELOW FORMATE(RCFM=VB,LRECL=1028)
Code:
SQL> SET ECHO OFF
SQL> SET HEADING OFF
SQL> SET TERMOUT OFF
SQL> SET FEEDBACK OFF
SQL> SET TRIMSPOOL ON
SQL> SET PAGESIZE 0
SQL> SET COLSEP ','
SQL> SELECT TZR,PROP_CODE,TO_CHAR(INV_DATE,'YYYY'),'3001',
2 TO_CHAR(INV_DATE,'YYYY-MM-DD'),'0',USER_NOTES
3 FROM OYT_XP_DAILY_SPREAD
4 WHERE INV_DATE BETWEEN TO_DATE('02/01/2018','MM/DD/YYYY')
3,BADPT,2018,3001,2018-02-01,0

3,MADPT,2018,3001,2018-02-02,0

3,CADPT,2018,3001,2018-02-03,0

After Sort i want ot extract only the below records from Input file and write it into outputfile.