如何使用批处理脚本合并两个文本文件? [英] How to merge two text files using batch script?
本文介绍了如何使用批处理脚本合并两个文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本文件作为A.TXT和B.txt与下面的内容:
I have two text files as A.txt and B.txt with the below contents:
A.TXT 的
A.txt
value_a1,value_a2
value_b
value_c
value_d
value_e1,value_e2
B.txt 的
B.txt
12,14
13
15
16
23,34
我要输出文件C.txt为
I want output file C.txt as
"value_a1","12","value_a2","14"
"value_b","13"
"value_c","15"
"value_d,"16"
"value_e1,"23","value_e2","34"
请指导我,因为我是新来的批处理脚本。
Please guide me through as I am new to Batch Script.
推荐答案
继code将工作:
@Echo off
echo. >>d.txt
type b.txt >>d.txt
set dec=1
For /F "usebackq tokens=1,* delims=, " %%a in ("a.txt") do call :File1 %%a %%b
set dec1=0
del d.txt
exit /b
:File1
SET str1=%~1
SET str2=%~2
SET Count=1
For /F "usebackq tokens=1,* skip=%dec% delims=," %%A in ("d.txt") do call :File2 %%A %%B
set /a dec=%dec%+1
exit /b
:File2
SET str3=%~1
SET str4="%~2"
IF %Count% EQU 1 (
IF %str4%=="" (
echo "%str1%","%str3%" >>c.txt
set /a Count=%Count%+1
) ELSE (
echo "%str1%","%str3%","%str2%",%str4% >>c.txt
set /a Count=%Count%+1)
)
exit /b
这篇关于如何使用批处理脚本合并两个文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文