- @echo off
-
- :choose
- echo.&echo 请选择操作类型:
- echo.&echo 1 - 比较两个文本并将相同内容输出
- echo.&echo 2 - 比较两个文本并将不同内容输出
- echo.&echo 3 - 两个文本内容合并后将相同内容只保留一个输出
- echo.&echo 0 - 退出批处理
-
- echo.&set choose=&set /p choose=选择要执行的序号:
- if %choose% equ 0 exit
- for /l %%a in (1,1,3) do if %choose% equ %%a (
- call :setfile
- call :%%a
- cls&echo.&echo 处理完毕!继续选择操作类型:
- goto :choose
- )
- cls&echo.&echo 输入的序号有误,请重新选择!&goto :choose
-
- :setfile
- echo.&set file1=&set /p file1=请输入要比较的第一个文件名:
- set file1=%file1:"=%
- echo.&set file2=&set /p file2=请输入要比较的第二个文件名:
- set file2=%file2:"=%
- echo.&set outfile=&set /p outfile=请输入最后结果保存的文件名:
- set outfile=%outfile:"=%
- goto :eof
-
- :1
- findstr /i /g:"%file1%" "%file2%">"%outfile%"
- goto :eof
-
- :2
- call :1
- findstr /i /v /g:"%outfile%" "%file1%">"%outfile%.bak"
- findstr /i /v /g:"%outfile%" "%file2%">>"%outfile%.bak"
- sort "%outfile%.bak">"%outfile%"
- del "%outfile%.bak"
- goto :eof
-
- :3
- (type "%file1%"&echo.&type "%file2%")>"%outfile%"
- cd.>"%outfile%.bak"
- for /f "delims=" %%i in ('type "%outfile%"') do (if not defined %%i set %%i=A & echo %%i>>"%outfile%.bak")
- move /y "%outfile%.bak" "%outfile%"
- goto :eof
复制代码
|