Can I split : 185 to :
Code: Select all
echo "i","%1:~0,15%","%1:~16,30%","%1:~31,k%","%1:~k+1,l%",....,"%1:~n,185%">>"z.txt"
Moderator: DosItHelp
Code: Select all
echo "i","%1:~0,15%","%1:~16,30%","%1:~31,k%","%1:~k+1,l%",....,"%1:~n,185%">>"z.txt"
alid0381 wrote:The result is like this form :Code: Select all
Nomi PNomi Addi DMAi CL.Mi ccRi
But, Can I make it like this form :Code: Select all
"i","Nomi ","PNomi ","Addi ","DMAi ","CL.Mi ","ccRi"
...
Aacini wrote: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
Code: Select all
...
"i","NomiPNomi ","Addi ","DMAi ","CL.Mi ","ccRi"
...
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem Define the lenghts of all fields
set /A numFields=0, recLen=0
for %%a in (15 15 10 lenOfDMAi lenOfCL.Mi lenOfccRi) do (
set /A numFields+=1
set /A len[!numFields!]=%%a, recLen+=%%a
)
set /A line=0, i=0, start=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 /L %%j in (1,1,%numFields%) do (
for /F "tokens=1,2" %%m in ("!start! !len[%%j]!") do set output=!output!,"!record:~%%m,%%n!"
set /A start+=len[%%j]
)
echo %output%
set input=!input:~%recLen%!
if defined input goto ProcessLine4
exit /B
Well it is just analog to, my above post:alid0381 wrote:I mean
Can I split : 185 to :Code: Select all
echo "i","%1:~0,15%","%1:~16,30%","%1:~31,k%","%1:~k+1,l%",....,"%1:~n,185%">>"z.txt"
The %1 is a command line parameter and no environment variable:penpen wrote:As the replacement extensions are only available for environment variables, and not for command line parameter variables: See "set /?".
So you have to store the command line parameter within a variable.
And you need to use delayedExpansion or a call construct to build the variable replacement command and then use it.
Code: Select all
...
for %%a in (15 15 10 lenOfDMAi lenOfCL.Mi lenOfccRi) do (
...
Code: Select all
...
for %%a in (10 15 15 8 4 7 9 10 7 80 5 2 3 10) do (
...