Batch file to compare the differences in two csv files

送分小仙女□ 提交于 2019-12-23 04:43:49

问题


I use windows 7. I have two csv files file1.csv and file2.csv

file1.csv

emp_id;salary
1;1000
2;2000
3;3000

file.csv

emp_id;salary
1;1000
2;2000
3;3000
4;4000
5;5000

I'm confused how to write a batch file. The batch file should output the should be a csv file showing the changes.

Sample output:

emp_id;salary
4;4000
5;5000

回答1:


You can use findstr to look for differences, and the /v parameter to display differences. Like so:

findstr /v /g:"file1.csv" "file2.csv"

Also:

for /f "delims=" %%a in (file1.csv) do (
    findstr "^%%a$" "file2.csv" >nul ||echo %%a
)

And using the fc command:

fc "file1.csv" "file2.csv"

For fc im sure you can use an if not errorlevel 1 echo No difference



来源:https://stackoverflow.com/questions/36315131/batch-file-to-compare-the-differences-in-two-csv-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!