Interleave files with CMD using echo

不羁的心 提交于 2019-12-02 19:31:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!