Dynamically Creating Files
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 42
- Joined: Wed Dec 26, 2007 1:58 am
- Location: India
Dynamically Creating Files
Hi,
I've a requirement like of below,
I'm reading a file where i've 2 columns (Column1 & Column2).
If this file has 10 records,then i've to create 10 files where the name of files should be based on the values from the coulmn1 & the content of the file be the values from Column2.
Example:
My Input file might be like
Column1 Column2
Seq1 Test1
Seq2 Test2
Seq3 Test3
Seq4 Test4
Seq5 Test5
Seq6 Test6
Seq7 Test7
Seq8 Test8
Seq9 Test9
Seq10 Test10
My Output files should be like
FileName Content
Seq1.txt Test1
Seq2.txt Test2
Seq3.txt Test3
Seq4.txt Test4
Seq5.txt Test5
Seq6.txt Test6
Seq7.txt Test7
Seq8.txt Test8
Seq9.txt Test9
Seq10.txt Test10
I was allowed only to use sequncers & parallel jobs.
Thanks in Advance.
I've a requirement like of below,
I'm reading a file where i've 2 columns (Column1 & Column2).
If this file has 10 records,then i've to create 10 files where the name of files should be based on the values from the coulmn1 & the content of the file be the values from Column2.
Example:
My Input file might be like
Column1 Column2
Seq1 Test1
Seq2 Test2
Seq3 Test3
Seq4 Test4
Seq5 Test5
Seq6 Test6
Seq7 Test7
Seq8 Test8
Seq9 Test9
Seq10 Test10
My Output files should be like
FileName Content
Seq1.txt Test1
Seq2.txt Test2
Seq3.txt Test3
Seq4.txt Test4
Seq5.txt Test5
Seq6.txt Test6
Seq7.txt Test7
Seq8.txt Test8
Seq9.txt Test9
Seq10.txt Test10
I was allowed only to use sequncers & parallel jobs.
Thanks in Advance.
Regards
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
-
- Participant
- Posts: 14
- Joined: Mon Mar 23, 2009 12:57 am
- Location: INDIA
Re: Dynamically Creating Files
Hi,
If you are sure about the no. of rows in the source then it can be done easily otherwise its almost impossible!
Regards
Boss
If you are sure about the no. of rows in the source then it can be done easily otherwise its almost impossible!
Regards
Boss
poornima.chandramouli wrote:Hi,
I've a requirement like of below,
I'm reading a file where i've 2 columns (Column1 & Column2).
If this file has 10 records,then i've to create 10 files where the name of files should be based on the values from the coulmn1 & the content of the file be the values from Column2.
Example:
My Input file might be like
Column1 Column2
Seq1 Test1
Seq2 Test2
Seq3 Test3
Seq4 Test4
Seq5 Test5
Seq6 Test6
Seq7 Test7
Seq8 Test8
Seq9 Test9
Seq10 Test10
My Output files should be like
FileName Content
Seq1.txt Test1
Seq2.txt Test2
Seq3.txt Test3
Seq4.txt Test4
Seq5.txt Test5
Seq6.txt Test6
Seq7.txt Test7
Seq8.txt Test8
Seq9.txt Test9
Seq10.txt Test10
I was allowed only to use sequncers & parallel jobs.
Thanks in Advance.
DS Info
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
No its not impossible unless it encounters any limitation of the product or operating system or mind , or the file definition is bad. One more thing if it doesn't worth that effort.
In this case read the file using cat command and get the output.
count the number of delimiters in this case field marks and run the routine in loop to get one line at a time and with first values create a file and write the second value in that file.
In this case read the file using cat command and get the output.
count the number of delimiters in this case field marks and run the routine in loop to get one line at a time and with first values create a file and write the second value in that file.
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.
Genius may have its limitations, but stupidity is not thus handicapped.
-
- Participant
- Posts: 42
- Joined: Wed Dec 26, 2007 1:58 am
- Location: India
Re: Dynamically Creating Files
This is not an interview question.
It is my requirement.
I was only allowed to use Parallel jobs & Sequencers to achieve this requirement.
It is my requirement.
I was only allowed to use Parallel jobs & Sequencers to achieve this requirement.
Regards
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
Re: Dynamically Creating Files
Once again Parallel jobs & Sequencers . Its confusing me. can you please answer my questions.poornima.chandramouli wrote:This is not an interview question.
It is my requirement.
I was only allowed to use Parallel jobs & Sequencers to achieve this requirement.
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.
Genius may have its limitations, but stupidity is not thus handicapped.
-
- Participant
- Posts: 42
- Joined: Wed Dec 26, 2007 1:58 am
- Location: India
Re: Dynamically Creating Files
We can use only parallel jobs & Sequencer Jobs(not server jobs)priyadarshikunal wrote:Once again Parallel jobs & Sequencers . Its confusing me. can you please answer my questions.poornima.chandramouli wrote:This is not an interview question.
It is my requirement.
I was only allowed to use Parallel jobs & Sequencers to achieve this requirement.
Regards
-
- Participant
- Posts: 42
- Joined: Wed Dec 26, 2007 1:58 am
- Location: India
Re: Dynamically Creating Files
poornima.chandramouli wrote:We can use only parallel jobs & Sequencer Jobs(not server jobs)priyadarshikunal wrote:Once again Parallel jobs & Sequencers . Its confusing me. can you please answer my questions.poornima.chandramouli wrote:This is not an interview question.
It is my requirement.
I was only allowed to use Parallel jobs & Sequencers to achieve this requirement.
Or
Only Parallel Jobs alone
Or
combination of both Parallel jobs & Sequencers
Regards
-
- Participant
- Posts: 42
- Joined: Wed Dec 26, 2007 1:58 am
- Location: India
Hi Shane,ShaneMuir wrote:Use an external file stage and in the output use an awk command to append each row to a file name called whatever value is in the first column.
Thanks for your response,Could you please explain a bit further.
Since i'm new for using External Filter stage & also how the values can be dynamically mapped to file names,because we are not sure of the number of records.
Thanks
Regards
I'll try to expand but my unix skills aren't that great.
Basically in your external file stage, pass it 2 rows, one being the file name (in your case the first column plus whatever extension you wish to give it), and then pass the rest of your columns as one column (with whatever delimiter your target file needs).
It in the destination program of the external file stage you would need something like
Set your Target method to Specific program.
Basically in your external file stage, pass it 2 rows, one being the file name (in your case the first column plus whatever extension you wish to give it), and then pass the rest of your columns as one column (with whatever delimiter your target file needs).
It in the destination program of the external file stage you would need something like
Code: Select all
awk '{nPosField1=index($0,",");print substr($0,nPosField1+1)>substr($0,1,nPosField1-1)}'
-
- Participant
- Posts: 14
- Joined: Thu Dec 13, 2007 2:57 am
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Shane means External Target, not External Filter. The command in the external target is a relatively straightforward awk command. Read the man pages on awk, or a good UNIX for beginners manual, for more information.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.