Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a command line Linux tool that will find and replace Hex representation of data in a binary file? Example Usage?

For example: 's/00FF00FFFF06500B49/11BB00BFFF06500B49/g'

share|improve this question
There's a similar question here. – Dennis Williamson Apr 9 '10 at 19:18
@Dennis Williamson, Agreed but those answers are more programmatic then an expected answer on ServerFault (i.e. several include non-sed/awk source code). – mctylr Apr 9 '10 at 19:35
up vote 1 down vote accepted

Perl Scirpt:

my $find_packed = pack "H*", '0100000000000000FF0A16731485400000000000FFA10201FF22FFFFFFFF0200';
my $repl_packed = pack "H*", '0100000000000000FF0A16731485400010FFC545FFA10201FF22FFFFFFFF0200';
my $file = do { local $/; <> };
$file =~ s/\Q$find_packed/$repl_packed/g;
print $file;


perl in_binary > out_binary

The above unpolished version seems to have worked for me, thanks to the guys in #perl on freenode :-)

share|improve this answer
I'm deleting my post about sed, it's not the right tool for this, sorry. – kbyrd Apr 9 '10 at 20:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.