|
Post by Rambo-X on Nov 23, 2020 3:08:03 GMT
Dear All, Good Day I am trying to get few numbers I have typed in 3 separate lines into 3 different txt files. I wrote this but guess my understanding is wrong the last number keeps getting to all 3 files. Can someone help me to get the line items separated to separate text files please? My Code 1 | FOR | EACH | LINE IN | F:\Test-in.txt | DO 2 | RUN ACTION | OUTPUT TO FILE | E:\out1.txt::APPEND::%LINE% 3 | FOR | NEXT 4 | RUN ACTION | OUTPUT TO FILE | F:\output2.txt::APPEND::%INTEGER% 5 | FOR | NEXT 6 | RUN ACTION | OUTPUT TO FILE | F:\output3.txt::APPEND::%INTEGER%
|
|
|
Post by Steve on Nov 23, 2020 9:25:57 GMT
Hi Rambo-X Yes your syntax is wrong. FOR | NEXT is the end of for block. More on FOR looping syntax is located on the condition page here www.turnssoft.com/conditions.html#for. e:\out1.txt 1 2 3 4 5 f:\test-in.txt 100 200 300 400 500 1 | FOR | EACH | LINE IN | F:\Test-in.txt | DO 2 | RUN ACTION | OUTPUT TO FILE | E:\out1.txt::APPEND::%LINE% 3 | FOR | NEXT e:\out1.txt 1 2 3 4 5 100 200 300 400 500
|
|
|
Post by Rambo-X on Nov 23, 2020 10:09:44 GMT
Unfortunately I think there was a communication error here...
What I have in my "test-in.txt" File,
123 456 789 112 556 887 968
What I need the Macro to do is break them into separate Files. So the example would be like, "out1.txt" contains :
123
"out2.txt" contains :
456
"out3.txt" contains :
789
so on,
I did try reading the above link for hours and didn't understand a way to get these lines to "separate files".
|
|
|
Post by Rambo-X on Nov 23, 2020 16:30:03 GMT
Is there anyways to get it done guys?
|
|
|
Post by Steve on Nov 23, 2020 18:43:54 GMT
Ah ok i see you what you mean.
You want each line in test-in.txt to be in a new file and each file name to be incremented by a variable. This is what you want:
1 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER99%::1 2 | FOR | EACH | LINE IN | F:\Test-in.txt | DO 3 | RUN ACTION | OUTPUT TO FILE | E:\out%INTEGER99%.txt::APPEND::%LINE% 4 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER99%::+1 5 | FOR | NEXT
|
|
|
Post by Rambo-X on Nov 24, 2020 8:39:13 GMT
Thanks a lot My Dear Friend...Thank you Thank you and Thank you... This game me Nightmares man.
|
|
|
Post by Rambo-X on Nov 24, 2020 15:41:49 GMT
Just asking as for further Clarification,
If I require to Dissect "an X number" of Lines ex: every 3 Lines ; to a new file how can we do it?
|
|
|
Post by Steve on Nov 24, 2020 21:55:11 GMT
Just asking as for further Clarification, If I require to Dissect "an X number" of Lines ex: every 3 Lines ; to a new file how can we do it? If I wanted only the third line in f:\test-in.txt to be appended to a new file under e:\out[number].txt I would use this: 1 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER99%::1 2 | FOR | EACH | LINE IN | F:\Test-in.txt | DO 3 | IF | INTEGER VARIABLE | %INTEGER99% | % | 3::=::0 | OUTPUT TO FILE | E:\out%INTEGER99%.txt::APPEND_NEWLINE::%LINE% 4 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER99%::+1 5 | FOR | NEXT At line 3 we do some basic math (https://www.turnssoft.com/conditions.html#integer_variable). We evaluate the value of integer99 to determine IF INTEGER99 MOD 3 is EQUAL to 0 (if integer99 can be divided by 3 with no remainder). If it can then we know that we have had three iterations of the for loop so therefore we must be on the the third line of the test-in.txt file.
|
|
|
Post by Rambo-X on Nov 24, 2020 23:21:26 GMT
Thanks a lot.
But my Question to be precise was not about the 3rd line... I am asking actually about pulling out of X "numbers" of lines, as per my example 3 Lines at a time, 3, 6, 9 so on. So the Out files would have 3 lines per file.
Thank you again.
|
|