Assuming we have this text files
*0000000000003000345800091600000000000002082019 0
*000000000000322322930002160000000DOU JIJEL 1
*000000000000306156240007000000000TIC TAHER 1
The header contains always what follows :
From position 1 to position 21 we have always this:
*00000000000030003458
which is an «unchangeable
» value. It contains 21 characters.
From position 22 to 34, we got 13 characters which represent the sum of the amounts contained in every line the text file from position 22 to 34.
To clarify ; if you look at the header you’ll see from position 22 to 34 :
0009160000000
which is 91 600 000,00
It’s an amount of money, which is the sum of the amounts in the first and second line.
First line : 0002160000000
which is 21 600 000,00
Second line : 0007000000000
which is 70 000 000,00
21 600 000,00+70 000 000,00=91 600 000,00
« If we have in the first line 3162160000000 it means the amount in 31 621 600 000,00 If we have in the first line 0000000541000 it means the amount is 5 410,00 »
From position 35 to 41, we have seven characters, which represent the number of amounts contained in the text file. We have From position 35 to 41 0000002, and we have two lines except the header, so the sum is 2. If for example we have 714 lines, the position 35 to 41 in the header will be 0000714, and so on.
So, if I have two text files, and I want to merge them together in one file, in a way that we’ll have: Only one header and All the lines in the text files. The lines of course will be unchanged. But the header will be changed as I explained above, in addition to that and from position 42 to position 62, will always be of the values or the characters contained in the header of the text files I want to merge, which are always the same. That means that the header will be changed only from position 22 to position 41.
I've managed to remove the headers, but the new header I write it manually
@echo off
setlocal enabledelayedexpansion
if exist output.txt del output.txt
set "var="
for /r %%i in (*.txt) do (
if "%%~nxi" NEQ "output.txt" (
set "var="
for /f "usebackq skip=1 delims=" %%b in ("%%~i") do (
set var=%%b
if "!var!" NEQ "" Echo !var!
))) >> output.txt
this code will remove the header of the text files
So I expect the new header to be calculated automatically