使用批处理文件,如何检查多个csv文件的第一行是否完全相同?

例如,我有3个CSV文件:CSV1,CSV2,CSV3

每个csv文件都具有这种格式-

Issue type,Issue key,Date,Status
1,2,30/12/2018,Available
1,5,31/12/2018,Available

我想检查所有3个csv文件的列名(例如,发行类型,发行密钥,日期,状态)是否匹配。如何批量执行此操作?

eryaa 回答:使用批处理文件,如何检查多个csv文件的第一行是否完全相同?

为了向您展示实际发生的情况,我已经做了很长一段路了。 我使用三个测试文件作为示例test1.csvtest2.csvtest3.csv

@echo off
for /f "delims=" %%i in ('type test1.csv') do set "test1=%%~i" & goto :check2
goto :eof
:check2
for /f "delims=" %%i in ('type test2.csv') do set "test2=%%~i" & goto :check3
goto :eof
:check3
for /f "delims=" %%i in ('type test3.csv') do set "test3=%%~i" & goto :final
goto :eof
:final
if "%test1%" == "%test2%" (set "onetwo=true") else (set "onetwo=false")
if "%test2%" == "%test3%" (set "twothree=true") else (set "twothree=false")
if "%test1%" == "%test3%" (set "onethree=true") else (set "onethree=false")
if "%onetwo%%twothree%%onethree%"=="truetruetrue" echo All 3 files have the same header
if "%onetwo%%twothree%%onethree%"=="falsefalsetrue" echo only 1 and 3 martches,but not 2
if "%onetwo%%twothree%%onethree%"=="truefalsefalse" echo only 1 and 2 martches,but not 3
if "%onetwo%%twothree%%onethree%"=="falsetruefalse" echo only 2 and 3 martches,but not 1
if "%onetwo%%twothree%%onethree%"=="falsefalsefalse" echo None of the headers match.
本文链接:https://www.f2er.com/3112336.html

大家都在问