Hope I am clearer this time.
I believe you were reasonably clear the first post.
Yes. It is still not a job for REXX. As i said before:
It is also not a good idea for a learning exercise as one should to learn to do appropriate things rather than inappropriate things.
Actually I am writing a file using REXX code which also has duplicate entries which I need to delete.
Might be a good idea to not
write the duplicates in the first place.
If you explain the total requirement, we may be better able to offer suggestions.
Something else you might want to consider is that most organizations do not allow REXX to process "business rules" which is what your process does. Even if it is running successfully in a development environment, there is no mechanism to promote it to production.