Page 1 of 1

Renaming a File with Current Date

Posted: Tue Feb 27, 2007 2:41 pm
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

Posted: Tue Feb 27, 2007 2:57 pm
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.

Posted: Tue Feb 27, 2007 3:18 pm
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

Posted: Tue Feb 27, 2007 3:24 pm
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

Posted: Tue Feb 27, 2007 3:58 pm
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.

Posted: Tue Feb 27, 2007 4:11 pm
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

Posted: Tue Feb 27, 2007 7:05 pm
by lstsaur
Try this:
cp Emp.txt `date +EMP%m%d%y.txt`