Repetitively read x lines from txt file and pass to called program
Posted: 17 Jun 2020 11:39
Hi all,
New to batch programming so...
I have a large text file with repeated sets of lines of data - same number of lines (35) each time.
I wish to create a batch file to repetitively read blocks of 35 lines, passing them to another program that will read them as if from stdin.
Once I get that working, I need to extract the 4 digit number prior to the word Solution on the first line of each set of lines (sample data below), and build a filename from that which will be added to the command line call...
I have got this far in testing - and am happy to move forward step by step.
But have reached two stumbling blocks.
1/. The line count isn't being incremented (or at least always displays 0).
2/. The second line of every set of my data (see below) is simply the word OFF. When it gets to the second line of any set there is no output of OFF, just press any key to continue... - is it because there is only one element in the line? I would prefer if the line was read complete into one variable.
If I put %%i and %lines% in the one echo statement, it outputs OFF 0... head scratching...
an example of a program I wish to pass the data to if the input was myfile.off
antiview myfile.off
Or, I can run antiview, paste the 35 lines on the command line and type ctrlz enter
When I have it working, there will be a more complicated command line which will still accept the same data, and hopefully, redirect output to a specified file, name of which is created by the batch file as mentioned above.
off2pov [options] [data] > Filename_from_4_Digits.pov
If all goes well, I will then call another program, pvengine64 [options] Filename_from_4_Digits.pov /EXIT to get it rendered to a .png
I realise there may need to be a method of waiting for each *.pov to be created before calling povray.
And, if all goes even better, delete the *.pov files and be left with just the .png's
Sample of data
# 111412135, 1 2, 1 3, 1 5, 1 7, 5, 0002 Solution 1 Seed 1 0.1 0.2 0.1 0.1
OFF
9 22
0.303530999103343 0.525731112119134 0.794654472291766
0.337320057246881 0.326071178562728 0.883115374959396
0.35463739892041 0.110488823890414 0.92845276405549
0.35463739892041 -0.110488823890414 0.92845276405549
0.113725895453813 0.455163328063184 0.883115374959396
0.143959750150644 0.249345601505837 0.957654614851438
0.171848502003268 -2.90837232769237E-17 0.985123389408267
-0.0859242510016338 0.148825168337131 0.985123389408267
-0.0859242510016338 -0.148825168337131 0.985123389408267
3 0 1 4
3 1 2 5
3 1 4 5
3 2 3 6
3 2 5 6
3 5 6 7
3 6 7 8
2 0 1 0
2 0 4 0
2 1 4 1
2 1 2 0
2 2 3 0
2 1 5 0
2 4 5 0
2 2 5 2
2 2 6 0
2 3 6 0
2 5 6 3
2 5 7 3
2 6 7 4
2 6 8 4
2 7 8 4
repeated too many times to have individual files...
New to batch programming so...
I have a large text file with repeated sets of lines of data - same number of lines (35) each time.
I wish to create a batch file to repetitively read blocks of 35 lines, passing them to another program that will read them as if from stdin.
Once I get that working, I need to extract the 4 digit number prior to the word Solution on the first line of each set of lines (sample data below), and build a filename from that which will be added to the command line call...
I have got this far in testing - and am happy to move forward step by step.
Code: Select all
@echo off
setlocal DisableDelayedExpansion
set /a lines = 0
for /f "usebackq delims=" %%i in ("icosa v05-5.txt") do (
echo %%i
echo %lines%
set /a lines += 1
pause
)
1/. The line count isn't being incremented (or at least always displays 0).
2/. The second line of every set of my data (see below) is simply the word OFF. When it gets to the second line of any set there is no output of OFF, just press any key to continue... - is it because there is only one element in the line? I would prefer if the line was read complete into one variable.
If I put %%i and %lines% in the one echo statement, it outputs OFF 0... head scratching...
an example of a program I wish to pass the data to if the input was myfile.off
antiview myfile.off
Or, I can run antiview, paste the 35 lines on the command line and type ctrlz enter
When I have it working, there will be a more complicated command line which will still accept the same data, and hopefully, redirect output to a specified file, name of which is created by the batch file as mentioned above.
off2pov [options] [data] > Filename_from_4_Digits.pov
If all goes well, I will then call another program, pvengine64 [options] Filename_from_4_Digits.pov /EXIT to get it rendered to a .png
I realise there may need to be a method of waiting for each *.pov to be created before calling povray.
And, if all goes even better, delete the *.pov files and be left with just the .png's
Sample of data
# 111412135, 1 2, 1 3, 1 5, 1 7, 5, 0002 Solution 1 Seed 1 0.1 0.2 0.1 0.1
OFF
9 22
0.303530999103343 0.525731112119134 0.794654472291766
0.337320057246881 0.326071178562728 0.883115374959396
0.35463739892041 0.110488823890414 0.92845276405549
0.35463739892041 -0.110488823890414 0.92845276405549
0.113725895453813 0.455163328063184 0.883115374959396
0.143959750150644 0.249345601505837 0.957654614851438
0.171848502003268 -2.90837232769237E-17 0.985123389408267
-0.0859242510016338 0.148825168337131 0.985123389408267
-0.0859242510016338 -0.148825168337131 0.985123389408267
3 0 1 4
3 1 2 5
3 1 4 5
3 2 3 6
3 2 5 6
3 5 6 7
3 6 7 8
2 0 1 0
2 0 4 0
2 1 4 1
2 1 2 0
2 2 3 0
2 1 5 0
2 4 5 0
2 2 5 2
2 2 6 0
2 3 6 0
2 5 6 3
2 5 7 3
2 6 7 4
2 6 8 4
2 7 8 4
repeated too many times to have individual files...