Linux binary compare

Vote 0 Votes

cmp -l file1 file2 | gawk '{printf "%08X %02X %02X\n", $1-1, strtonum(0$2), strtonum(0$3)}'
原本 cmp 的 offset 是十進位(從1開始), ASCII是八進位
gawk 把 cmp 的輸出結果轉成十六進位, 並把 offset-1, 因為一般的 Hex Editor 都是從 0 開始, 類似這樣
00011DEF 10 08
00011DF0 0E 07
輸出結果跟 Windows 的 fc/b 一樣

可寫成 script 方便使用
if [ -z $2 ] ; then
  echo "`basename $0` {file1} {file2}"
  cmp -l $1 $2 | gawk '{printf "%08X %02X %02X\n", $1-1, strtonum(0$2), strtonum(0$3)}'

ref. How do I compare binary files in Linux?

About this Entry

This page contains a single entry by Pank published on August 30, 2014 3:38 PM.

wxMEdit was the previous entry in this blog.

VMware Thick Provision or Thin Provision is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives