简体   繁体   English

比较二进制文件并仅打印匹配行的偏移量

[英]compare binary files and print only offset of matching line

For regular files I can use the comm command to find common lines. 对于常规文件,我可以使用comm命令查找常见行。

For example we have two files 例如我们有两个文件

$ cat f1
line1
line2
line3
line4
line5

$ cat f2
line1
line20
line30
line4
line5

Its compared like: 其比较像:

$ comm -12 f1 f2
line1
line4
line5

How to find the offset of matching lines and also how to do comparison for two binary files and print matching line offset? 如何找到匹配行的偏移量,以及如何比较两个二进制文件并打印匹配行的偏移量?

I've been using things like diff , cmp , comm for past 1hr, unable to figure this out. 我过去1个小时一直在使用diffcmpcomm类的东西,无法弄清楚。

EDIT 1: Not exact solution but found vbindiff it helps a bit. 编辑1:不是确切的解决方案,但发现vbindiff有所帮助。

You are probably looking for cmp : 您可能正在寻找cmp

cmp - compare two files byte by byte cmp-逐字节比较两个文件

$ cmp f1 f2
f1 f2 differ: byte 12, line 2

$ cmp -b f1 f2
f1 f2 differ: byte 12, line 2 is  12 ^J  60 0

$ cmp -bl f1 f2
12  12 ^J    60 0
13 154 l     12 ^J
14 151 i    154 l
15 156 n    151 i
16 145 e    156 n
17  63 3    145 e
18  12 ^J    63 3
19 154 l     60 0
20 151 i     12 ^J
21 156 n    154 l
22 145 e    151 i
23  64 4    156 n
24  12 ^J   145 e
25 154 l     64 4
26 151 i     12 ^J
27 156 n    154 l
28 145 e    151 i
29  65 5    156 n
30  12 ^J   145 e
cmp: EOF on f1

From man cmp : 来自man cmp

-b , --print-bytes -b ,--print-bytes

print differing bytes 打印不同的字节

-l , --verbose -l ,--verbose

output byte numbers and differing byte values 输出字节数和不同的字节值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM