Latest file retrieval

We are using UNIX awk command to retrieve the latest filename corresponding to a particular pattern in a given directory. Command is as below:
ls -ltr $DIR | grep -i <pattern> | tail -1 | awk 'BEGIN{}{if($0 ~ /^-/){ print $9 }}END{}'
As we are unsure of whether the target system supports the usage of awk, we came up with the below alternative command which produces the same result:
ls -ltr $DIR | grep -i <pattern> | tail -1 | cut –f 2 –d”:” | cut –f 2 –d” “
However this depends on ls –ltr returning the date in the format “25 Feb 12:38” so not very reliable.
Is there a better way to achieve the same?

> As we are unsure of whether the target system supports the usage of awk, we came up with the below alternative command which produces the same result:
> ls -ltr $DIR | grep -i <pattern> | tail -1 | cut =96f 2 =96d=94:=94 | cut =96f 2 =96d=94 =93
> However this depends on ls =96ltr returning the date in the format =9325 Feb 12:38=94 so not very reliable.
> Is there a better way to achieve the same?
--

If I am reading this right, you are wanting the name of the latest file that has a filename that follows a certain pattern. If that is correct I can think of a couple ways of doing it:
ls -ltr|grep -i <pattern>|tail -1|cut -c 58-80
That is where the last column starts on my machine.
The other way would assume that you know what the last filename was:
find . -name <old_filename>|grep <pattern>

Copyright 1998-2015 Ziff Davis, LLC (Toolbox.com). All rights reserved. All product names are trademarks of their respective companies. Toolbox.com is not
affiliated with or endorsed by any company listed at this site.