Add Trailer Record With Count

I need to add a trailer record with count to some files using unix.
The file has the structure as below, so basically what I need is to count all records, including trailer record and append to the end of the file trailer record (structure of the new record to be added i.e. TRL 6)