Renaming a File with Current Date

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
yashwin.yaskhi
Participant
Posts: 21
Joined: Fri Feb 16, 2007 12:09 pm

Renaming a File with Current Date

Post by yashwin.yaskhi »

Hi All,

I asked this Question a week ago and I got a partial solution.

My ETL job creates a external table as Emp.txt in Netezza server. The requirement is this Emp.txt should be named like Emp022707.txt(it should have current date appended to it). Earlier I got a solution from this forum where in I tried with
cp Emp.txt Emp`date +%m%d%y`.txt

using this logic, I am able to copy the file with new name as 'Emp022707.txt?'....I am not sure why that question mark is coming along. Moreover I am not able to access that new file. Can anyone help me to write a script which can be called from ETL job which does the renaming? I am getting the same problem with 'mv' command too.

Thanks in Adance
Sachin
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

Where are you issuing the comand
cp Emp.txt Emp`date +%m%d%y`.txt
Your statement is right, you should be getting correct results.
The ? getting appended is mysterious.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
yashwin.yaskhi
Participant
Posts: 21
Joined: Fri Feb 16, 2007 12:09 pm

Post by yashwin.yaskhi »

Narasimha,
The file will be placed in Netezza server. So, initially I checked running that command manually in the unix server. Its copying the file and remaning it too but not sure why that '?' mark is seen. Moreover, I cannot see the contents of the new file.

Thanks for your reply
Sachin
yashwin.yaskhi
Participant
Posts: 21
Joined: Fri Feb 16, 2007 12:09 pm

Post by yashwin.yaskhi »

And to be more precise, I am not using the command directly in unix client.
I using that command in a shell script which is placed in after-job sub routine of my ETL job
Sachin
Aparna_A
Participant
Posts: 21
Joined: Wed Nov 09, 2005 11:16 pm

Post by Aparna_A »

hi yashwin,

Why are you creating the file and then trying to rename it?

If you cannot change the existing file name, then that's fine but you can parameterize the filename in the DataStage job.
Add a new parameter CycleDate to your list of parameters and in the datastage job the filename can be coded as Emp#CycleDate#.txt.
Aparna
yashwin.yaskhi
Participant
Posts: 21
Joined: Fri Feb 16, 2007 12:09 pm

Post by yashwin.yaskhi »

Aparna,
Thanks for your reply but let me be very clear this time.
See,
My Datastage job has a target which creates an external table. For your ref:
create external table DB..Emp SAMEAS DB..Emp_v USING (DATAOBJECT ('/nz/hrms/data/target/Emp.txt') COMPRESS FALSE FORMAT 'text' DELIMITER '|' );
Now this statement creates an file Emp.txt in Netezza server '/nz/hrms/data/target/'.
Now the user's requirement is that they want the file in Netezza server rather than datastage server. That is the reason I used external table.

Now, the format of the file should be EmpMMDDYY.txt The file should pick up the date of every sunday(job is scheduled on sunday)
So, only alternative left for me is to use shell scripts to rename the file..
cp Emp.txt Emp`date +%m%d%y`.txt works fine when used directly but includes a '?' mark when included in a shell script.

I hope its clear.

Thanks
Sachin
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

Try this:
cp Emp.txt `date +EMP%m%d%y.txt`
Post Reply