1) to extract the last record from file A and compare the extracted record with records from file B, If a match is found place duplicate records in file C,
If file B also has duplicate records, they needs to be placed in file C,
2) File D to contain unique records
Your description of what you want is very confusing and your example doesn't help.
to extract the last record from file A and compare the extracted record with records from file B, ...
The last record in file A is the 55555 record - there's no match for this in File B, so I don't understand your 1) rule.
In File C, where do the two 22222 records come from (file A or file B or both)? Why do the 44444 records come from fileA and fileB?
You need to show a better example of input and expected output that makes it clear where each output record comes from. You need to do a better job of explaining the "rules" for getting from input to output.
Frank, Very Sorry for creating confusion.
Instead of writing file A , I have written file B and vice-versa
Correcting the rule 1
I have to compare the last record from file B i.e. (44444) with the records from file A.
Now the last record (44444) from file B matches with record from file A, these matching records will be placed in file C.
Also the file A has duplicate records within itself i.e. (22222) so they will also be placed in file C.
Now the records left in file A will be unique and will be put to file D