【发布时间】:2013-01-14 20:55:10
【问题描述】:
我有两个要比较的文件。这些行有时间戳,可能还有一些我想在匹配算法中忽略的其他内容,但是如果匹配算法在文本的其余部分发现差异,我仍然希望输出这些项目。例如:
1c1
< [junit4] 2013-01-11 04:43:57,392 INFO com.example.MyClass:123 [main] [loadOverridePropFile] Config file application.properties not found: java.io.FileNotFoundException: /path/to/application.properties (No such file or directory)
---
> [junit4] 2013-01-11 22:16:07,398 INFO com.example.MyClass:123 [main] [loadOverridePropFile] Config file application.properties not found: java.io.FileNotFoundException: /path/to/application.properties (No such file or directory)
不应该发出但是:
1c1
< [junit4] 2013-01-11 04:43:57,392 INFO com.example.MyClass:123 [main] [loadOverridePropFile] Config file application.properties not found: java.io.FileNotFoundException: /path/to/application.properties (No such file or directory)
---
> [junit4] 2013-01-11 22:16:07,398 INFO com.example.MyClass:456 [main] [loadOverridePropFile] Config file application.properties not found: java.io.FileNotFoundException: /path/to/application.properties (No such file or directory)
应该发出(因为行号不同)。请注意,仍会发出时间戳。
如何做到这一点?
【问题讨论】:
-
一种方法是删除您不想匹配的信息,并仅使用相关数据制作文件的截断副本。但是,您必须保留准确的行号。然后您使用行号返回到您想要的文件并完整获取相关行。
标签: shell