自动执行目录差异,同时忽略文件中的某些特定行
我需要比较两个目录,并生成某种差异的结构化输出(文本文件很好)。也就是说,输出可能看起来像这样:
file1 exists only in directory2
file2 exists only in directory1
file3 is different between directory1 and directory2
我不关心格式,只要信息存在即可。第二个要求是我需要能够在比较两个文件时忽略某些字符序列。 Araxis Merge 具有此功能:您可以输入正则表达式,并且任何唯一区别在于与该正则表达式匹配的字符序列的文件将被报告为相同。
这将使 Araxis Merge 成为一个很好的候选者,但是,到目前为止,我还没有找到生成差异的结构化输出的方法。即使使用命令行参数启动 consolecompare.exe,它也只是打开一个显示差异的 Araxis GUI 窗口。
那么,以下任一情况是否存在?
- 一种让 Araxis Merge 将差异结果打印到文本文件的方法?
- 另一个在忽略某些字符的情况下进行比较的实用程序 序列,并产生结构化输出?
如果这样的实用程序作为 Python 的模块或插件存在,则额外加分。请记住,这必须完全通过命令行/Python 脚本完成 - 没有 GUI。
I need to compare two directories, and produce some sort of structured output (text file is fine) of the differences. That is, the output might looks something like this:
file1 exists only in directory2
file2 exists only in directory1
file3 is different between directory1 and directory2
I don't care about the format, so long as the information is there. The second requirement is that I need to be able to ignore certain character sequences when diffing two files. Araxis Merge has this ability: you can type in a Regex and any files whose only difference is in character sequences matching that Regex will be reported as identical.
That would make Araxis Merge a good candidate, BUT, as of yet I have found no way to produce a structured output of the diff. Even when launching consolecompare.exe with command-line argumetns, it just opens an Araxis GUI window showing the differences.
So, does either of the following exist?
- A way to get Araxis Merge to print a diff result to a text file?
- Another utility that do a diff while ignoring certain character
sequences, and produce structured output?
Extra credit if such a utility exists as a module or plugin for Python. Please keep in mind this must be done entirely from a command line / python script - no GUIs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在某种程度上,普通的旧
diff
命令就可以做到这一点,即比较目录内容并忽略与特定正则表达式模式匹配的更改(使用-I
选项)。来自 man bash:
快速演示:
To some extent, the plain old
diff
command can do just that, i.e. compare directory contents and ignoring changes that match a certain regex pattern (Using the-I
option).From man bash:
Quick demo: