Regex and backreference to replace in binary file

view story

http://www.unix.com – Hello to all, I have this sed script that replaces hex strins within a binary file. As you can see, I want to replace all bytes 4X with 2X (where X could take values 0 to F). Code: sed -e 's/\x40/\x20/g' -e 's/\x41/\x21/g' -e 's/\x42/\x22/g' -e 's/\x43/\x23/g' -e 's/\x44/\x24/g' -e 's/\x46/\x26/g' -e 's/\x47/\x27/g' file I would like to know if it is possible to use regex and backreference for this in sed or perl, etc? I'd like to be able to do something like this, but is not working: Code: sed -e 's/\x4\(.\)/\x2\1/g' file Thanks in advance for any help. (HowTos)