2011-09-22 38 views
1

我需要比較兩個目錄,並生成某種結構化輸出(文本文件很好)的差異。也就是說,輸出可能看起來像這樣:在忽略文件中的某些特定行時自動執行目錄比較

file1 exists only in directory2 
file2 exists only in directory1 
file3 is different between directory1 and directory2 

我不關心格式,只要信息在那裏。第二個要求是我需要在區分兩個文件時忽略某些字符序列。 Araxis Merge具有這種能力:您可以鍵入正則表達式,並且任何文件的唯一區別在於匹配該正則表達式的字符序列將被報告爲相同。

這將使Araxis合併一個很好的候選人,但是,我還沒有找到方法來產生diff的結構化輸出。即使使用命令行參數argumetns啓動consolecompare.exe,它也會打開顯示差異的Araxis GUI窗口。

那麼,是否存在以下任一情況?

  • 一種獲取Araxis合併以將差異結果打印到文本文件的方法?
  • 另一個實用程序,它可以在忽略某些字符 序列的同時進行差異化,並生成結構化輸出?

額外的功勞,如果這樣的實用工具作爲Python的模塊或插件存在。請記住,這必須完全從命令行/ python腳本完成 - 沒有GUI。

+0

如果使用會發生什麼['consolecompare'(http://www.araxis.com/merge/command_line.html)而不是'比較'? – NullUserException

回答

1

在某種程度上,簡單的舊diff命令可以做到這一點,即比較目錄內容並忽略與某個正則表達式模式匹配的更改(使用-I選項)。

man bash

-I regexp 
     Ignore changes that just insert or delete lines that match regexp. 

快速演示:

[[email protected]]$ diff images/ images2 
Only in images2: x 
Only in images/: y 
diff images/z images2/z 
1c1 
< zzz 
--- 
> zzzyy2 

[[email protected]]$ # a less verbose version 
[[email protected]]$ diff -q images/ images2 
Only in images2: x 
Only in images/: y 
Files images/z and images2/z differ 

[[email protected]]$ # ignore diffs on lines that contain "zzz" 
[[email protected]]$ diff -q -I ".*zzz.*" images/ images2/ 
Only in images2/: x 
Only in images/: y 
+0

幾乎忘了,這是在窗戶上運行。 –

+0

我正在調查windows端口的bash,因爲這看起來非常誘人! –

+0

MinGW應該能夠爲您提供一個bash端口和所有* nix的好東西。還有cygwin。 –

相關問題