You could maybe make a script with a loop that looks for the applying transactions of a transaction and then continue until you find the end of the line and then start deleting backwards. It would be cumbersome and you would have to store values and transaction type in an array for the path, but it should be doable.