批处理命令合并csv行 [英] batch command merge csv rows
本文介绍了批处理命令合并csv行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题陈述.我有2个csv文件.我想将两个文件的前两行合并为一个.我运行我的代码,似乎我的第二个标头丢失了,数据追加到了第三行.
My problem statement. I have 2 csv files. I want to merge first 2 rows of both files together become one.I run my code it seems like my second header is missing and the data append to 3rd row.
文件A:
A B
1 2
文件B:
C D
3 4
预期结果:
A B C D
1 2 3 4
我的代码:
@echo off
cd /d "C:\my csv directory"
set first=true
setlocal enabledelayedexpansion
(for %%x in (*.csv) do (
if !first!==true (
type "%%x"
echo.
set first=false
) ELSE (
more +1 "%%x"
)
))> c:\destination\newfile.csv
失败结果:
a,b
1,2
3,4
推荐答案
要合并两个文件中的列,您可以并行读取两个文件
To merge columns from two files you can read two files in paralllel
:: Merge2Files.cmd FileA FileB
@Echo Off & SetLocal EnableDelayedExpansion
Set "FileA=FileA.txt"
Set "FileB=Fileb.txt"
<%FileB% (For /f "delims=" %%A in (%FileA%) Do (
Set "B="&Set /P "B="
Echo:%%A,!B!
)) >New-%FileA%
这篇关于批处理命令合并csv行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文