使用win批处理脚本比较SIDE和SIDE

我正在做以下,但有两个问题(赢得2003年):

  1. 输出包括匹配的第一行和最后一行:-(
  2. 输出不是并排的

这两个问题能解决吗? build议(我试过/ nnn和/ lb选项)

脚本:

:bof ::Swith off echo - the @ switch off echo for this line @echo off :: Clear screen cls :: Keep Locals contained to this batch file setlocal :: Set the two files and check that they exist set fileA=X:\tst\pfsrc\alex.txt set fileB=X:\tst\cbsrc\alex.txt if not exist "%fileA%" echo %fileA% not found & goto :end if not exist "%fileB%" echo %fileB% not found & goto :end :: del .old file rename previous output file to .old rem if exist X:\tst\cbsrc\resultPF1.old del X:\tst\cbsrc\resultPF1.old rem if exist X:\tst\cbsrc\resultPF1.txt rename X:\tst\cbsrc\resultPF1.txt *.old :: compare files FC /c /l /n /w %fileA% %fileB% :end 

第一个input文件:

 new line line1 line2 line3 line4 insert new line and another new line line5 line6 line7 and a line here line8 line9 line10 what is this line? line11 

第二个input文件:

 new line alex hart was here line5 line6 line7 line8 line here line9 line10 

OUTPUT:

 Comparing files X:\TST\PFSRC\alex.txt and X:\TST\CBSRC\ALEX.TXT ***** X:\TST\PFSRC\alex.txt 1: new line 2: line1 3: line2 4: line3 5: line4 6: insert new line 7: and another new line 8: line5 ***** X:\TST\CBSRC\ALEX.TXT 1: new line 2: alex 3: hart 4: was 5: here 6: line5 ***** ***** X:\TST\PFSRC\alex.txt 10: line7 11: and a line here 12: line8 13: line9 ***** X:\TST\CBSRC\ALEX.TXT 8: line7 9: line8 10: line here 11: line9 ***** ***** X:\TST\PFSRC\alex.txt 15: what is this line? 16: line11 ***** X:\TST\CBSRC\ALEX.TXT ***** 

FC命令始终将差异显示为依次列出的一组行; 没有办法显示差异并排。 您可以获得FC输出并在批处理程序中处理它,以便差异并排显示,但是您必须认识到,该程序应该识别不同的特殊情况,以便正确显示两个部分并排。

前段时间我写了这样一个程序, 我把它叫做“FComp.bat”,你可以在这里下载。 例如:

 C:\> FComp.bat /C /L /N /W 1stInputFile.txt 2ndInputFile.txt Comparing files 1stInputFile.txt and 2NDINPUTFILE.TXT ============================== SECTION MODIFIED ============================= 1: new line | 1: new line 2: line1 | 2: alex 3: line2 | 3: hart 4: line3 | 4: was 5: line4 | 5: here 6: insert new line | 6: line5 7: and another new line 8: line5 ============================== SECTION MODIFIED ============================= 10: line7 | 8: line7 11: and a line here | 9: line8 12: line8 | 10: line here 13: line9 | 11: line9 OLD SECTION DELETED AT END OF FILE =========================================== - 15: what is this line? - 16: line11