How to read files by Server Creation date wise?

Hi All,

I would have many files in the server with
xyz*.dat -- Static file name
Physical files:

xyz1.dat - 01PM
xyz2.dat - 02PM
xyz3.dat - 03PM

In present version we are using

for f in $file_name
       do     
       fname=`ls $f | grep -v ^'[.]\|[..]'$ | sed s/' '/'\\ '/g`
....
sqlldr ......
....
       done <ireq_id.tmp

This is reading files irrespective of file creation date&time, we need it to pick first come first serve type..

Please advise..
Thanks in Advance.

Get the list of file names in $file_name sorted with time

If there are not too many files in the directory you could do this:

ls -t $file_name |
while read fname
do
...
done

and don't forget to use double quotes when using referencing $fname:

some_cmd "$fname"

If there are many file names you could:

ls -t |
while read fname
do
  case $fname in
    $file_name);;
    *) continue
  esac
   ....
done

Thank you.. hiten.r.chauhan
But how to sort by time at for f in $file_name ## file_name=xyz*.dat

Thank you. Scrutinizer
My main loop is for, that get the physical file name and submit sqlldr and move the file to other locatoin. So how the two options suggested by you would help.

@Dharv you can probably use the lines that are currently in your while loop below the line where fname is being set (I used three dots there ... ). So your main loop would change from a for loop to a while loop. Otherwise you would need to show us more of your script..