考虑到我的CSV具有标头,我编写了一个批处理以将当前目录中的多个CSV合并为一个。但是我得到的文件在每一行的末尾都包含一个空格字符。
@echo off
pushd %~dp0
setlocal ENABLEDELAYEDEXPANSION
set cnt=1
for %%i in (*.csv) do (
if !cnt!==1 (
for /f "delims=" %%j in ('type "%%i"') do echo %%j >> merged.csv
) else if %%i NEQ merged.csv (
for /f "skip=1 delims=" %%j in ('type "%%i"') do echo %%j >> merged.csv
)
set /a cnt+=1
echo !cnt!
)
答案 0 :(得分:0)
就像史蒂芬(Stephan)所评论的那样,您明确地告诉它添加一个空格,但是作为另一个选择,也许它将是一个较短的版本?
@echo off
pushd %~dp0
for %%i in (*.csv) do if "%%i" NEQ "merged.csv" type "%%i" | more +1 >> merged.csv
答案 1 :(得分:0)
merged.csv
排除在自身之外。@echo off
pushd %~dp0
set "flag="
for /f "delims=" %%i in ('dir /B *.csv ^|find /v "merged.csv" ') do (
if not defined flag (
copy "%%i" merged.csv
set flag=anything
) else more +1 "%%i" >>merged.csv
)
popd