Looping through a text file

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Looping through a text file

Post by kogads »

Hello all,

I am designing a sequencer which does the following
--using execute_command stage i am opening a text file a.txt
a.txt contents:
123,456789
234,567891
--next in start_loop_activity I need each line of a.txt to go to the iteraion
ie., i the first iteration 123,456789 should be passed
So,in start_loop_activity I selected

Loop type as List loop
delimited values as #Execute_Command.$CommandOutput#
delimiter "\n"

My problem is in the loop i am getting all the 2 lines of a.txt
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Since you're on Windows \n probably isn't your line terminator. Leaving that aside, I have always preferred to translate the line terminator into a different delimiter (such as pipe or some other printable character) so that it can be clear in the Start Loop activity what the delimiter is.

So an Execute Command activity to read the file and translate its line terminators, passing its output to the Start Loop activity.

I've seen other sites use a User Variables activity to accomplish translation of the line terminators.

If necessary you can remove the final delimiter (empty line) as part of this processing.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Sorry it was unix

Post by kogads »

Hey ray,

Thanx for the response..OS was Unix.Sorry about that.
Here is what i am testing::::::::::::::::::::::

1.using exec_comm_activity i am opening the file
cat -e a.txt (so that delimiter can be a $)
123,4567
234,5678
2.In the start_loop_activity
List loop
Delimited value:#Execute_Command.$CommandOutput#
Delimiter:$
3.Inside the loop i have a exec_comm_activity wherein i am doing
echo #StartLoop_Activity.$Counter#
4.End loop

In the log,
Iteration 1:Executed: echo 123,4567
Reply=0
Output from command ====>
123,4567

iteration2:
1.Executed: echo
Reply=234,5678
Output from command ====>

2.Command echo did not finish OK, reply = '-1'


Why am I not able to echo the second line in iteration 2
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Tried with keeping delimiters inside the file

Post by kogads »

Also,tried by directly keeping the delimiter "$" inside the file a.txt
123,4567$
234,5678

and then just did
cat a.txt in exec_command_activity initially
greggknight
Premium Member
Premium Member
Posts: 120
Joined: Thu Oct 28, 2004 4:24 pm

Post by greggknight »

If I understand what you are doing. You are using a text file to control the loop in a sequence.

If so why don't you just have a single continous line with delimited values.

123,234,543,2345,4567,...........

The reason I say this is because if you set the count to a parameter list the value in the list is a delimited list on a single line.

if you enter the list as 123,234,345,567,
678,567,678

It will not work. It is expecting a single line delimited list.
"Don't let the bull between you and the fence"

Thanks
Gregg J Knight

"Never Never Never Quit"
Winston Churchill
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Thank you so much for the help

Post by kogads »

Hey greg,

Thanks a lot for the prompt response figured out the problem.
greggknight
Premium Member
Premium Member
Posts: 120
Joined: Thu Oct 28, 2004 4:24 pm

Post by greggknight »

Could you elaborate on what it was?
"Don't let the bull between you and the fence"

Thanks
Gregg J Knight

"Never Never Never Quit"
Winston Churchill
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Post by kogads »

Hey just an Elaboration:

The text file has
Some_name1,OutputFolder1
Some_name2,OutputFolder2

likewise...And now i am getting a file(DUMMY) which should have the prefix as Some_name and it should be copied to corresponding folder.
eg:Some_name1_DUMMY should be copied to OutputFolder1
Some_name2_DUMMY should be copied to OutputFolder2

So, I am doing a cat on text file and for each line I am doing a loop.
Inside the loop i have written a script to cut each line based on delimiter ',' and copy the file to outputfolder as mentioned.
Post Reply