LS -T Output in find

I have prepared a script with ls -t to fetch latest file and compare with duplicates i use below

ls -t *xml |awk 'BEGIN{FS="_"}{if (++dup[$1] >= 2) print}'

However for large size folder ls command not working. so i tried with

find ./ -type f \( -iname "*.xml" \) | sort |awk 'BEGIN{FS="_"}{if (++dup[$1] >= 2) print}'

but newly created files is not extracted first so i am unable to retain newly created file.

i need to change find command in similiar way output of ls -t command. Please help.

Thank you in advance.

As long as you're just concerned with files in a single directory (and not in files in subdirectories), there is no need to switch from ls to find . Try:

ls -t | awk -F_ '/xml$/ && dup[$1]++'

Can you qualify what you mean by "ls command not working"? Arg list too long? If so, and you can't increase that limit, you could either try breaking the command down to get fewer files ( (ls -t [a-g]*; ls -t [h-n]*; etc..) | ... ), or use find with either the -prune or -maxdepth options to prevent reading subdirectories, if that's a concern.