List only the recent log files

Hi Friends,

I have a list of files in a directory as shown below. It is basically in this format-> yymmdd.hhmmss.filename.out

I want to list the latest log of each file. ie. the lastest a.out, b.out, c.out, which means I am looking for only the below 3 files out of these 5 files:

All I can think of is have the file names, a.out, b.out, c.out in a input file and have a for loop. The loop would grep for the file name and take the latest one; it is something like,

I want to know if we have any other smarter way of doing this without using any loops as the number of files to scan are more.

Try this:

ls -lt | 
awk -F "[ .]" 'a[$11]{next}
{a[$11]=1;print $9, $10, $11, $12}' OFS="." | sort -t. -k3

Hi,
It worked out fine. I did a small change with the code you gave as shown below:

I am not sure why awk -F"[ .]" did not work. I got just "..." as output when I used it.

Thank you very much for you help. I really appreciate your brilliance.

"ls -lut" might be better (assuming you really want the latest used rather than just latest created)