Hello,
I need help, please.
I'm trying to read a txt file, something like this:
01dkdkdkkd
01dfksdfkdfksd
02 dffv fvfv dfv
03 frerf erferf efr
03 erferf erferfe
And i want to create new files named with the 2 first character of the line and put the rest of the line inside the file.
I try a lot of things and i just don't get it.
@echo off
for /F %%a in (prod.txt) do
(
set linha=%%a
echo %%a >>%linha:~0,2%mati.pc rem this create just one file name 01mati.pc with all the lines inside
echo %linha% rem this give me allways the last line why???
)
thanks in advance
Reading a txt file and create others
Moderator: DosItHelp
Re: Reading a txt file and create others
You need to use delayed expansion
Re: Reading a txt file and create others
I use
SETLOCAL ENABLEDELAYEDEXPANSION
and still doesn't work
I got the same result
SETLOCAL ENABLEDELAYEDEXPANSION
and still doesn't work
I got the same result
Re: Reading a txt file and create others
Well,
I got it. I also replace de %linha% for !linha!
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "tokens=*" %%a in (prod.txt) do (
set linha=%%a
set nlinha=!linha:~0,2!
echo %%a >>!nlinha!mati.pc
echo !linha!
echo !nlinha!
)
ENDLOCAL
I got it. I also replace de %linha% for !linha!
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "tokens=*" %%a in (prod.txt) do (
set linha=%%a
set nlinha=!linha:~0,2!
echo %%a >>!nlinha!mati.pc
echo !linha!
echo !nlinha!
)
ENDLOCAL