To add and take average of second column entry(time stamp in hh:mm:ss) in file p10.txt (eg Retrieve_generic_assembly_(CP) is coming three times. So add all 3 entry and take average).
Similarly do it for p20.txt.
Write a new file output.txt that should have entry for all first column and avg entry of file p10.txt in second column and avg entry of p20.txt in third column and take difference of second and third column in fourth column.
Then, please reformat your code with proper indenting, and insert comments telling yourself (and then us) at which place you are expecting to achieve what. For instance, I cannot see average calculus anywhere, not even an attempt thereof.
Hold on, you might get better answers, and nicer ones.
The you could use the subroutine above to calculate both avg H:M:S--including their difference with a prepended minus sign, where appropriate. The last chellenge is to figure out how to print the Retrieve_ lines in your desired order.