问题
How could I interleave files line by line with
cmd.exe
with help of read, grep, echo, etc?
File1.txt with the context:
Aaaaaaa1
Aaaaaaa2
Aaaaaaa3
File2.txt with the context:
Bbbbbbb1
Bbbbbbb2
Bbbbbbb3
I would like to combine File1.txt and File2.txt in other file (OUTCOME.txt) in this way:
Aaaaaaa1
Bbbbbbb1
Aaaaaaa2
Bbbbbbb2
Aaaaaaa3
Bbbbbbb3
回答1:
You need a method to read from two files in parallel. This is possible by using two methods at the same time (<file1 set /p
and for /f ... in (file2)
):
@echo off
setlocal enabledelayedexpansion
<file2.txt (
for /f "delims=" %%a in (file1.txt) do (
set /p b=
echo %%a
echo !b!
)
) >outcome.txt
来源:https://stackoverflow.com/questions/48152975/interleave-files-with-cmd-using-echo