Wow! I hate to try to write code when the specifications are incomplete and we are forced to guess in order to produce any code that may run. @alid0381: you should realize that show program code trying to explain something never works: if the code is wrong,
and we don't know what its purpose is, how we could identify any errors on it? You always should explain your problem in plain English and include both the
real input data and the desired output.
Anyway, this is my attempt to try to hit on the solution to this problem:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem I have a text file "CLOLG.txt" that contains 4 Ligns :
rem Ligne 1....
rem Ligne 2....
rem Ligne 3....
rem Nom1 PNom1 Add1 DMA1 CL.M1 ccR1Nom2 PNom2 Add2 DMA2 CL.M2 ccR2Nom3 PNom3 Add3 DMA3 CL.M3 ccR3 ... Nomi PNomi Addi DMAi CL.Mi ccRi ...
rem I want the result as following :
rem Ligne 1....
rem Ligne 2....
rem Ligne 3....
rem "1","Nom1 ","PNom1 ","Add1 ","DMA1 ","CL.M1 ","ccR1"
rem "2","Nom2 ","PNom2 ","Add2 ","DMA2 ","CL.M2 ","ccR2"
rem "3","Nom3 ","PNom3 ","Add3 ","DMA3 ","CL.M3 ","ccR3"
rem ...
rem "i","Nomi ","PNomi ","Addi ","DMAi ","CL.Mi ","ccRi
set recLen=31
set /A line=0, i=0
for /F "delims=" %%a in (CLOLG.txt) do (
set "input=%%a"
set /A line+=1
if !line! leq 3 (
echo !input!
) else (
call :ProcessLine4
)
)
goto :EOF
:ProcessLine4
set /A i+=1
set output="%i%"
set record=!input:~0,%recLen%!
for %%b in (%record%) do set output=!output!,"%%b "
echo %output:~0,-2%"
set input=!input:~%recLen%!
if defined input goto ProcessLine4
exit /B
The "recLen" variable should be set to the record lenght, 185 in your case. This program may show a maximum of 44 sub-records of 185 characters each. The value given in the program is the right one for the example data:
Code: Select all
Ligne 1....
Ligne 2....
Ligne 3....
Nom1 PNom1 Add1 DMA1 CL.M1 ccR1Nom2 PNom2 Add2 DMA2 CL.M2 ccR2Nom3 PNom3 Add3 DMA3 CL.M3 ccR3Nomi PNomi Addi DMAi CL.Mi ccRi
Output:
Code: Select all
Ligne 1....
Ligne 2....
Ligne 3....
"1","Nom1 ","PNom1 ","Add1 ","DMA1 ","CL.M1 ","ccR1"
"2","Nom2 ","PNom2 ","Add2 ","DMA2 ","CL.M2 ","ccR2"
"3","Nom3 ","PNom3 ","Add3 ","DMA3 ","CL.M3 ","ccR3"
"4","Nomi ","PNomi ","Addi ","DMAi ","CL.Mi ","ccRi"
Antonio