Command line tools to replace bytes in a file

You can achieve it with dd command. Here's an example:

$ hexdump StringComparison  | head -1
0000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00

$ printf '\x11\x11\x11' | dd of=StringComparison bs=1 seek=4 count=3 conv=notrunc
3+0 records in
3+0 records out
3 bytes transferred in 0.000293 secs (10238 bytes/sec)

$ hexdump StringComparison  | head -1
0000000 cf fa ed fe 11 11 11 01 03 00 00 80 02 00 00 00

Explanation:

  • of = input file
  • bs = block size
  • seek = position (offset)
  • notrunc = do not truncate the output.