Find the latest file based on the date in the filename

Hi,

We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it.

Files are
PQR123.PLL.M989898.201308012254.gpg
PQR123.PLL.M989898.201308081254.gpg
PQR123.PLL.M989898.201308151554.gpg
PQR123.PLL.M989898.201308221454.gpg
PQR123.PLL.M989898.201308291354.gpg

So from the above files PQR123.PLL.M989898.201308291354.gpg is latest file since it was sent on August 29 at 1:54 pm. I need to get the date and timestamp of it which is "201308291354". Naming convention of the file always remains the same except 4th field is DATE AND TIME.

Need to use an awk command to get it.

Thanks,

From original post:

As per your input,

ls | awk -F\. 'm<$4{m=$4;f=$0} END{print f}'
1 Like