使用批处理脚本逐行合并两个文本文件 [英] Merge Two text files line by line using batch script
本文介绍了使用批处理脚本逐行合并两个文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个文本文件; A.txt和B.txt,我想使用批处理脚本将它们合并为C.txt.
I have 2 text files; A.txt and B.txt and I want to merge them to make C.txt using a batch script.
但是(这是棘手的部分),我希望这样做,因此A.txt的每一行都附加一个空格,然后是B.txt的第一行,然后是新行,其中第一行来自A,第二行来自B依此类推,直到到达B的末尾,然后我们从A的第二行开始.
However (here's the tricky part) I wish to do it so each line from A.txt is appended with a space then the first line from B.txt then a new line with the first line from A and the second from B and so on until the end of B is reached and then we start with the second line of A.
我知道我的措词不好,所以这是一个例子:
I know I haven't worded this well so here's an example:
A.txt;
1
2
3
4
5
B.txt;
Z
Y
X
W
V
T
R
所以C.txt就应该有;
So C.txt would have;
1 Z
1 Y
1 X
1 W
1 V
1 T
1 R
2 Z
2 Y
等
推荐答案
@echo off
for /f "delims=" %%a in (a.txt) do (
for /f "delims=" %%b in (b.txt) do (
>>c.txt echo %%a %%b
)
)
这篇关于使用批处理脚本逐行合并两个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文