Here is a for loop to save each line of a text file to its own variable:
@echo off
setlocal enableextensions enableDelayedExpansion
set count=0
for /f "tokens=*" %%a in (file.txt) do (
set /a count=!count! + 1
set var_!count!=%%a
)
endlocal
I would like to save the content of each variable to a separate new text file. How can I do this? I tried the following. But it does not work, because !var_!count!! is a variable inside a variable.
@echo off
setlocal enableextensions enableDelayedExpansion
set count=0
for /f "tokens=*" %%a in (file.txt) do (
set /a count=!count! + 1
set var_!count!=%%a
echo !var_!count!!>file_!count!.txt
)
endlocal
@echo off
setlocal enableextensions enableDelayedExpansion
set count=0
for /f "tokens=*" %%a in (file.txt) do (
set /a "count+=1"
set "var_!count!=%%a"
for %%b in (!count!) do >file_!count!.txt echo !var_%%b!
)
endlocal
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다