使用echo使文件与CMD交织 [英] Interleave files with CMD using echo
本文介绍了使用echo使文件与CMD交织的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在的帮助下与$ p $ b 逐行插入文件读取,grep,回显等 cmd.exe
File1.txt与上下文:
Aaaaaaa1
Aaaaaaa2
Aaaaaaa3
File2.txt,上下文:
Bbbbbbb1
Bbbbbbb2
Bbbbbbb3
I希望以此方式将File1.txt和File2.txt合并到其他文件(OUTCOME.txt)中:
Aaaaaaa1
Bbbbbbb1
Aaaaaaa2
Bbbbbbb2
Aaaaaaa3
Bbbbbbb3
解决方案
您需要一种方法来并行读取两个文件。这可以通过同时使用两种方法来实现((file2)中的/ f ... < file1 set / p
和 for / f ...
):
@echo off
setlocal enabledelayedexpansion
< file2.txt((
for / f delims = %% a in(file1.txt)in do(
set / pb =
echo %% a
echo!b!
)
)> outcome.txt
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
解决方案
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
这篇关于使用echo使文件与CMD交织的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文