I have few files in a directory, I need to pick the oldest one for processing.
For Exp: I have below files in /tmp directory:
Sample_0000237826-001_xyz.dat Sample_0000437564-001_xyz.dat Sample_0000237826-002_xyz.dat Sample_0000137294-003_xyz.dat
So my script should first sort the files on the basis of 1st set of 10 digit numbers in the file name I.e. nnnnnnnnnn, and in case for the first set of 10 digit number, if it gets multiple entries, then it should sort on the next set of 3 digit numbers I.e. nnn , and it should pick the oldest one.
Once I have picked up that file for processing, I will delete it from the directory. So it won't appear during the next run.
Hence for 1st run, I should pick the file: Sample_0000137294-003_xyz.dat
For 2nd run, I should pick: Sample_0000237826-001_xyz.dat
For 3rd run, I should pick: Sample_0000237826-002_xyz.dat
and so on.
Guys forgot to add one more thing, these files will be copied from remote server to my local server one by one as mentioned above, hence for copying I am using "rsync". Hence, please let me know if the below provided solution will work with rsync command as well or not.
awkscript you have so far, where it goes wrong and what the error message is (if applicable).
Sample_) is the same for every file, globbing should sort in that order (so
for f in *.datwould do).