How to get source file's name into a transformer?
Moderators: chulett, rschirm, roy
How to get source file's name into a transformer?
Hi,
I have a sequential file in source, which name is like FILENAME_YYYYMMDD.
I want to get the "YYYYMMDD" part of the filename in order to load it in a table.
Do you have any idea please?
Thanks in advance.
I have a sequential file in source, which name is like FILENAME_YYYYMMDD.
I want to get the "YYYYMMDD" part of the filename in order to load it in a table.
Do you have any idea please?
Thanks in advance.
Do it at the OS level. Do a
Now you have that name in a file. Read it in your job and load it in the table. You can run this command in the before job subroutine 'ExecSH'
Code: Select all
ls <dir path>| grep "FILENAME" | awk -F"\_" '{print $2}' > result.txt
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Easiest way to do this is on initialization of a Stage Variable in a Transformer. Write a DS Function to do a CALL DSExecute and run the command to get the filename and format the results. This will only be done once when the stage starts. Set the derivation of the stage variable to itself (FRED = FRED). Now just use the stage variable where desired.
![Wink :wink:](./images/smilies/icon_wink.gif)
![Wink :wink:](./images/smilies/icon_wink.gif)
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Did I give a Server answer to a PX question again?trobinson wrote:I get the impression Mr. Bland is referring to a Server job.
![Embarassed :oops:](./images/smilies/icon_redface.gif)
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
You know, you just sit and read thru about 20 Server posts, then a PX one comes thru and you don't mentally switch gears. It's not like I'm switching between here and other work at the same time ![Crying or Very sad :cry:](./images/smilies/icon_cry.gif)
![Crying or Very sad :cry:](./images/smilies/icon_cry.gif)
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
PX Sequential stage can put the name of the file(s) into a column you specify. You'll have to trim off the unwanted bits to keep just the date portion and then cast it into a properly typed column.
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
I tried to use File Name Column option in the sequential stage with a Read Method set to File Pattern and using a wildcard for my filename as FILENAME* (where my real file name is still FILENAME_YYYYMMDD).
Then I get this result in the output column "FILENAME*". I wonder why it returns me the wildcard, because I want to catch the date instead of the wildcard!!!!
Thank you all.
Then I get this result in the output column "FILENAME*". I wonder why it returns me the wildcard, because I want to catch the date instead of the wildcard!!!!
Thank you all.