Help me in this script fast

i have log files that represent names, times and countries,
each name come once in country but may in diff times
i need at end each name visited which country and its [ last time of visit ]

USA | Tony | 12:25:22:431
Italy | Tony | 09:33:11:212    ****
Italy| John | 08:22:12:349 
France | Adam | 14:22:42:981
Italy | Tony | 08:22:42:212    ****
Italy | Tony | 04:22:42:212   ****
Italy | Tony | 18:22:42:212   ****
USA | Adam | 14:22:42:981

i want the output to be :

USA | Tony | 12:25:22:431
Italy | Tony | 18:22:42:212  / we discarded other as this is the latest time/ 
Italy| John | 08:22:12:349
France | Adam | 14:22:42:981
USA | Adam | 14:22:42:981

i have tired this code but it take very huge time so help me to get more smarter script or take a little time

while [1]
do 
for name in file.txt | cut -d/| -f2 | uniq -d 
do 
grep name file.txt | sort -n -k2  | tail -1 >> output.txt 
done 
done 

but this script output is

Italy | Tony | 18:22:42:212   
Italy| John | 08:22:12:349
France | Adam | 14:22:42:981

which is wrong , it only get least day per name.

I just tried this with GNU sort and awk and it seems to work fine:

sort -r -k5 t3 | awk '!a[$1,$3]++'

PS: This record has no space between "Italy" and the pipe character.

Italy| John | 08:22:12:349
1 Like

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums