一个批处理变量嵌套的例题

一个网友给的题目,两个文本合并成一个。

文本1内容:

1.xxxxx:
2.xxxxx:
3.xxxxx:

文本2内容

1.a 2.b 3.c

合并后的内容:

1.xxxxx: a
2.xxxxx: b
3.xxxxx: c

方法

@echo off & setlocal enabledelayedexpansion
set n=0
for /f "tokens=2,4,6 delims=. "  %%i in (2.txt) do (
 set m1=%%i&set m2=%%j&set m3=%%k
 for /f "delims="  %%a in (1.txt) do (
 set /a n+=1
 call set mm=%%m!n!%%
 echo %%a !mm!
 )
)

我并不满意这个答案,因为方法比较取巧只是应付了网友的题目,但是如果文件内容较多的话,这个方法是行不通的,只是因为有一个变量嵌套的例子,所以记下来,方便以后查阅!

bat-pcl_test大神的方法(参数传递)

@echo off & setlocal enabledelayedexpansion
cd d:\test
for /f "tokens=1* delims=." %%i in (1.txt) do (
set /a n+=2
call :loop "%%i %%j" !n!
)
pause & exit
:loop
echo %1
echo %2
pause
set s=%1
for /f "tokens=%2 delims=. " %%a in (2.txt) do echo;%s:~1,-1%%%a
goto :eof

这才是好方法啊!

你可能感兴趣的:(一个批处理变量嵌套的例题)