Dynamically Creating Files

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

poornima.chandramouli
Participant
Posts: 42
Joined: Wed Dec 26, 2007 1:58 am
Location: India

Dynamically Creating Files

Post by poornima.chandramouli »

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.
Regards
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

This can be best done in routines.
I was allowed only to use sequncers & parallel jobs.
What you mean by this line.

Sequences & parallel jobs
or
Sequencers and parallel jobs only in sequences.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Is it an interview Q ?
sharantheboss
Participant
Posts: 14
Joined: Mon Mar 23, 2009 12:57 am
Location: INDIA

Re: Dynamically Creating Files

Post by sharantheboss »

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 :roll:



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
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

No its not impossible unless it encounters any limitation of the product or operating system or mind 8) , 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.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
poornima.chandramouli
Participant
Posts: 42
Joined: Wed Dec 26, 2007 1:58 am
Location: India

Re: Dynamically Creating Files

Post by poornima.chandramouli »

This is not an interview question.

It is my requirement.

I was only allowed to use Parallel jobs & Sequencers to achieve this requirement.
Regards
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Re: Dynamically Creating Files

Post by priyadarshikunal »

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.
Once again Parallel jobs & Sequencers . Its confusing me. can you please answer my questions.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
poornima.chandramouli
Participant
Posts: 42
Joined: Wed Dec 26, 2007 1:58 am
Location: India

Re: Dynamically Creating Files

Post by poornima.chandramouli »

priyadarshikunal wrote:
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.
Once again Parallel jobs & Sequencers . Its confusing me. can you please answer my questions.
We can use only parallel jobs & Sequencer Jobs(not server jobs)
Regards
poornima.chandramouli
Participant
Posts: 42
Joined: Wed Dec 26, 2007 1:58 am
Location: India

Re: Dynamically Creating Files

Post by poornima.chandramouli »

poornima.chandramouli wrote:
priyadarshikunal wrote:
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.
Once again Parallel jobs & Sequencers . Its confusing me. can you please answer my questions.
We can use only parallel jobs & Sequencer Jobs(not server jobs)
Or
Only Parallel Jobs alone
Or
combination of both Parallel jobs & Sequencers
Regards
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

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.
poornima.chandramouli
Participant
Posts: 42
Joined: Wed Dec 26, 2007 1:58 am
Location: India

Post by poornima.chandramouli »

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.
Hi Shane,

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
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

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

Code: Select all

awk '{nPosField1=index($0,",");print substr($0,nPosField1+1)>substr($0,1,nPosField1-1)}'
Set your Target method to Specific program.
nirav.parikh
Participant
Posts: 14
Joined: Thu Dec 13, 2007 2:57 am

Post by nirav.parikh »

In server jobs we could have done it using output as Folder Stage. wonder what's the equivalent for Parellel jobs.
Thanks & Regards
Nirav
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

ray.wurlod wrote:Shane means External Target, not External Filter.
Whoops! My bad.
Post Reply