File nane with date
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 68
- Joined: Wed Jan 10, 2007 11:24 pm
File nane with date
Hi All,
I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"
I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....
Waiting for your reply.
I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"
I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....
Waiting for your reply.
ETL DEVELOPER
Watch The Time Cycle, You Will Have All Answers.
Watch The Time Cycle, You Will Have All Answers.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 68
- Joined: Wed Jan 10, 2007 11:24 pm
-
- Premium Member
- Posts: 301
- Joined: Thu Jul 14, 2005 10:27 am
- Location: Melbourne, Australia
- Contact:
If your concern with the Unix option is that you don't want another 'asset' to have to manage outside the DataStage environment then couldn't you just supply the 'script' in the filename specification?
E.g. Something like ...
I've been working in a purely PX environment for quite some time and don't remember if this will work in server - so apologies in advance if it's not appropriate to your environment.
John.
E.g. Something like ...
Code: Select all
MyFilename_`date +%Y%m%d-%H%M%S`.txt
John.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 301
- Joined: Thu Jul 14, 2005 10:27 am
- Location: Melbourne, Australia
- Contact:
Jolly good.
Ray - Let me know if you're ever running a "Parallel to Server" transition class!
John.
Ray - Let me know if you're ever running a "Parallel to Server" transition class!
John.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 224
- Joined: Tue Sep 24, 2002 7:32 am
- Location: Denver, CO USA
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 86
- Joined: Wed Apr 02, 2008 2:32 am
- Location: Bangalore
answered....just repeating..in case you may have 4gotten
use #DSJobStartDate# macro in the filename.
eg. c:\data\target_file_#DSJobStartDate#.txt
only you get date as 2008_04_23 if that is acceptable.
Nice time to ask another question.....
Is there some way we can create or Modify an existing DS Macro?
use #DSJobStartDate# macro in the filename.
eg. c:\data\target_file_#DSJobStartDate#.txt
only you get date as 2008_04_23 if that is acceptable.
Nice time to ask another question.....
Is there some way we can create or Modify an existing DS Macro?
-
- Participant
- Posts: 2
- Joined: Tue Feb 19, 2008 4:40 pm
Re: File nane with date
Kshitij Rawat wrote:Hi All,
I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"
I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....
Waiting for your reply.
Hi all,
Even my client need the file with date as mentioned above, however he needs version number also.
For example, the output file format should be FILENAME_DD_MM_YYYY_XX
where XX is version number.
If due to some reason job is run twice a day, the file should have XX values as 01 for the first time and 02 for the second time.
Even the client is specific for date format too.
Please help !!
Surendra Kumar Sharma
-
- Premium Member
- Posts: 301
- Joined: Thu Jul 14, 2005 10:27 am
- Location: Melbourne, Australia
- Contact:
Using the 'script' approach I outlined previously you can specify your own date format. E.g. DD_MM_YYYY would be ...
What are the criteria for incrementing the version number? Every job run? If so, you could store the value in an environment variable and use a before-Job ExecSH to increment it ...
Then refer to that environment variable in your filename specification:
There are other approaches which I'm sure other posters will provide if needed.
John.
Code: Select all
MyFilename_`date +%d_%m_%Y`.csv
Code: Select all
MYVAL=`expr $MYVAL + 1`
Code: Select all
MyFilename_`date +%d_%m_%Y_$MYVAL`
John.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
-
- Participant
- Posts: 2
- Joined: Tue Feb 19, 2008 4:40 pm
The job is schedule to run everyday. So idealy there will be only one version per day. But if due to some reason, you run the job twice a day, then it should create second version.jhmckeever wrote:Using the 'script' approach I outlined previously you can specify your own date format. E.g. DD_MM_YYYY would be ...What are the criteria for incrementing the version number? Every job run? If so, you could store the value in an environment variable and use a before-Job ExecSH to increment it ...Code: Select all
MyFilename_`date +%d_%m_%Y`.csv
Then refer to that environment variable in your filename specification:Code: Select all
MYVAL=`expr $MYVAL + 1`
There are other approaches which I'm sure other posters will provide if needed.Code: Select all
MyFilename_`date +%d_%m_%Y_$MYVAL`
John.
For the next day. version should be set back to 01 again.
I appriciate above solution, but it would be great if somebody tells me solution without script.
Surendra Kumar Sharma
-
- Premium Member
- Posts: 301
- Joined: Thu Jul 14, 2005 10:27 am
- Location: Melbourne, Australia
- Contact:
It might help if you told us why you don't / won't / can't use a shell-based solution.
An alternative is to construct a DSBasic routine:
- Use the system date to construct a filename mask (E.g. MyFile_DD_MM_YYYY_*)
- Take a look at the relevant directory to see if any of today's files exist yet (sort the output)
- Get the highest sequence number from today's files (if any)
- Generate the appropriate filename as your routine's return value (using highest sequence number + 1)
- Call this routine from a job sequence using a User Variables activity
- Reference the routine's variable as an input parameter to the job creating the file.
Actually you could get the latest of today's files with a combination of ls -1, sort, and head commands.
Hope your reason for avoiding the shell solution is good enough to justify all the extra effort!
John.
An alternative is to construct a DSBasic routine:
- Use the system date to construct a filename mask (E.g. MyFile_DD_MM_YYYY_*)
- Take a look at the relevant directory to see if any of today's files exist yet (sort the output)
- Get the highest sequence number from today's files (if any)
- Generate the appropriate filename as your routine's return value (using highest sequence number + 1)
- Call this routine from a job sequence using a User Variables activity
- Reference the routine's variable as an input parameter to the job creating the file.
Actually you could get the latest of today's files with a combination of ls -1, sort, and head commands.
Hope your reason for avoiding the shell solution is good enough to justify all the extra effort!
John.
Last edited by jhmckeever on Fri May 02, 2008 12:17 am, edited 1 time in total.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>