我有一个批处理文件和一个文本文件,我希望从该文本文件中获取每两个字符并将其作为变量保存在批处理文件中作为变量aka
txt.bat
[][][]
batch.bat
px1=[] px2=[] px3=[]
我希望为一定数量的行和双倍数量的双字符执行此操作。
答案 0 :(得分:1)
@echo off
setlocal EnableDelayedExpansion
set amount=8
set i=0
set "first="
rem I have a Text file
for /F "delims=" %%a in ('cmd /U /C type textFile.txt^| find /V ""') do (
rem I want to get every two characters from that file...
if not defined first (
set "first=%%a"
) else (
rem and save it as a variable in the batch file...
set /A i+=1
set "px!i!=!first!%%a"
set "first="
rem and repeat until the file reaches set amount of variables
if !i! equ %amount% goto continue
)
)
:continue
set px
TextFile.txt的:
[][][]
abcdef
1234567890
输出:
px1=[]
px2=[]
px3=[]
px4=ab
px5=cd
px6=ef
px7=12
px8=34
答案 1 :(得分:0)
在您的文件中尝试使用"file.txt"
它将列出变量然后暂停。
这使用名为repl.bat
的帮助程序批处理文件 - 从https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
将repl.bat
放在与批处理文件相同的文件夹中或放在路径上的文件夹中。
@echo off
setlocal enabledelayedexpansion
type "file.txt"|repl "(..)" "$1\r\n" x >file.tmp
set c=100
for /f "delims=" %%a in (file.tmp) do (
set /a c+=1
set num=!c:~-2!
set "px[!num!]=%%a"
)
set px[
del file.tmp
pause