![批处理文件合并两个文本文件](https://linux22.com/image/1455298/%E6%89%B9%E5%A4%84%E7%90%86%E6%96%87%E4%BB%B6%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6.png)
我有两个文本文件,需要像这样合并它们:
文本文件 1
[][][]
[][][]
文本文件 2
******
******
******
输出
******
[][][] ******
[][][] ******
我已经在这里看过了: https://stackoverflow.com/questions/17097036/merge-two-text-files-line-by-line-using-batch-script 它给了我这个:
for /f "delims=" %%a in (1.txt) do (
for /f "delims=" %%b in (2.txt) do (
>>3.txt echo %%a %%b
)
)
但该脚本会循环直到文本均匀。如下所示:
[][][] ******
[][][] ******
[][][] ******
[][][] ******
[][][] ******
[][][] ******
答案1
请参考解决方案这里
我再次发布该解决方案
@echo off
set f1=1.txt
set f2=2.txt
set "sep= " % tab %
(
for /f "delims=" %%a in (%f2%) do (
setlocal enabledelayedexpansion
set /p line=
echo(!line!!sep!%%a
endlocal
)
)<%f1%