Page 1 of 1

Looping through a text file

Posted: Tue May 03, 2011 12:02 pm
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

Posted: Tue May 03, 2011 2:39 pm
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.

Sorry it was unix

Posted: Tue May 03, 2011 3:16 pm
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

Tried with keeping delimiters inside the file

Posted: Tue May 03, 2011 3:23 pm
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

Posted: Tue May 03, 2011 9:15 pm
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.

Thank you so much for the help

Posted: Thu May 05, 2011 7:39 am
by kogads
Hey greg,

Thanks a lot for the prompt response figured out the problem.

Posted: Thu May 05, 2011 7:42 am
by greggknight
Could you elaborate on what it was?

Posted: Thu May 12, 2011 1:23 pm
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.