unix file fetch by timestamp

218 views Asked by At

I have a list of files that get added to my work stream. They are csv with a date time stamp to indicate when they are created. I need to pick up each file in the order of the datetime in the file name to process it. Here is a sample list that I get:

Workprocess_2016_11_11T02_00_12.csv
Workprocess_2016_11_11T06_50_45.csv
Workprocess_2016_11_11T10_06_18.csv
Workprocess_2016_11_11T14_23_00.csv

How would I compare the files to search for the oldest one and work towards the chronological newer file? The day the files are dumped is the same, so I can only use from the timestamp in file name.

1

There are 1 answers

3
glenn jackman On

The beneficial aspect of that date time format is that it sorts the same lexically and chronologically. So all you need is

for file in *.csv; do
 mv "$f" xyz
 process xyz
done