I am new to Unix scripting and here is what I am looking for. We are sometime required to strip records from our input data file because the job fails due to erroneous record. We strip by record number. So lets take a typical file. A header record, data and then a trailer record (that contains the total count of file and looks like this: TR5009P6160480001001000023911 (this is a real example).
"TR50" is what all trailer records start with "09P6160480" is what we call a reference number for the job. "001001000023911" is the total number of records in the file.
Now Lets say I want to delete record number "4301" then I would first make a backup copy of the file and call it "filename.backup". Then I would open the original file using "vim". Then I do "set number" and then type "4301 G" to go that record. Then I copy the record to a different file to send it to business so they can look at it and then strip the record out and reduce the count of trailer record by one. In case above the new trailer record would be "TR5009P6160480001001000023910". I save the file and restart the failed jobs.
Can someone help me write a script to automate this. How can I automate the process of copying a record and email it to business before stripping it.