I have a flat file, which has a header, Some 'P' records, some 'S' records and a trailer.
In o/p i wish to omit the 'S' records
O/p file should have header. 'P' records and trailer.
Trailer should have the total count of available 'P' records (count should exclude header and trailer).
No, seeing this I got more qns. Here you've 2 output files which is not mentioned in your original post.
Are you trying to split the input file into two files - one each for "P" and "S" records? If yes, how the header/trailer records should like? Should it be the same for both the output files except for the count? You need to do a better job of explaining what exactly you want to achieve.
--Header contains branch number as zeroes (helps to identify header)
--Each record contains several details and an indicator at the 684th position 'P' or 'S', indicating primary or secondary record
--Trailer contains several details, but branch number for trailer will be 9999999, and it will have a total of the number of records ('P' or 'S') at position 28, length 8
file 1 should contain header (branch number 0)
records with ind 'P'
Trailer should contain all the details as they were in i/p file except for position 28, which will contain count of all 'P' records
file 2 should not contain header
records with ind 'S'
trailer should have all details as it was in i/p file except at loaction 28, that has count of all 'S' records.
sunnychopra's "solution" will NOT preserve the information in the trailer record as you requested because it just rebuilds certain fields in the trailer record. It also does NOT use the positions you specified for the fields.
Here's a DFSORT/ICETOOL job that will actually do what you asked for based on what you've said in your posts: