i have a file with the following content:
1005
1010
1011
1012
1013
1014
1009
1015
1006
77
1016
1017
1018
1019
1020
1021
1022
1023
1008
i want to read those lines into an array, sort them and write out chunks with 5 elements into a new file
the output file should looks like this (five elements each line.)
xyz 77,1005,1006,1008,1009
xyz 1010,1011,1012,1013,1014
...
my current batch script looks like this:
@echo off &setlocal disabledelayedexpansion
Sort Knot_unsort.dat>Knot_sort.dat
set /A i=0
for /F "delims=" %%a in (Knot_sort.dat) do (
set /A i+=1
call set array[%%i%%]=%%a
)
call set n=%%i%%
for /L %%i in (1,1,%n%) do (
set /a b = %%i %% 5
if %b% == 0 (
:: does not work
)
call echo %%b%%
)
sorting the content and reading the lines into a array works. but after that i dont know how to concat five elements into a new variable and write them back into a new file. i tried to use modulo but the if statement is not working.
for /F "delims=" %%a in ('sort Knot_unsort.dat') do (, given the numbers always consist of 4 figures; in the second loop you must of course readarray[%%i]; you could output the array elements bycall < nul set /P _="%%array[%%i]%%"to avoid a trailing line-break, then prependxyzand append,or a line-break conditionally, depending on the index%%i...Sort Knot_unsort.dat>Knot_sort.dat