Linux: August 2014 Archives

Linux binary compare

user-pic
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 方便使用
#!/bin/bash
if [ -z $2 ] ; then
  echo "`basename $0` {file1} {file2}"
else
  cmp -l $1 $2 | gawk '{printf "%08X %02X %02X\n", $1-1, strtonum(0$2), strtonum(0$3)}'
fi

ref. How do I compare binary files in Linux?

Recent Entries

About this Archive

This page is an archive of entries in the Linux category from August 2014.

Linux: July 2014 is the previous archive.

Linux: September 2014 is the next archive.

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

Linux: Monthly Archives

Monthly Archives