Pick latest file with respect to time

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
murali
Participant
Posts: 54
Joined: Mon Sep 12, 2005 11:38 pm

Pick latest file with respect to time

Post by murali »

Hi,
I need to pick latest file from the following using latest time value .
for example

Code: Select all

1) ABC020720061310.txt
2) ABC020720061510.txt
3) ABC020720060610.txt

In this ABC is the name with which the file name starts and 02072006(DDMMYYYY) is the date and 1310(24:00 HRS format) is the time.

 
In the above three file I need to pick the 2nd one which is having the latest time value.
Thanks in advance.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

How these files are getting created ?
Can you know the latest timestamp without looking at the directory?
If yes then use a parameterized sequential file.
If no, use something outside ds (may be perl)(me thinks) to know the file name, use Execute Command stage (sequence job) to get the timestamp and use it as a parameter for the (server job) sequential file.
Success consists of getting up just one more time than you fall.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Use

Code: Select all

ls -lart | tail -1
to get the latest file and cut it to get the filename alone and pass it as parameter as specified.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Too bad they're on a Windows server. :?

You could use a regular 'dir' command and find the last entry, or this and take the first:

Code: Select all

dir /b /o-n *.txt
Bare format, Order by name reversed. Coding this using DSExecute makes the 'get the first entry' easy as the variable used to capture the screen output is an array, so it would be:

Code: Select all

ScreenOutput<1>
Substitute the actual name of your variable. Last would be a little trickier but certainly feasible.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply