0

I have binary file that I want to replace with shell script 0xaa,0xbb,0xcc,0xdd with 0x11,0x22,0x33,0x44

I can get 0xaa,0xbb,0xcc,0xdd into shell script like $1 but how can I replace it with 0x11,0x22,0x33,0x44 without sed?

3
  • 4
    Welcome to SO, please be more clear in your question(like which script you are talking about, please do mention it in your question). Also it is always recommended to mention 3 important things 1- Sample of input, 2- Sample of output 3- efforts which you have put in order to solve your problem in code tags. Please add them clearly and do let us know. Commented Feb 4, 2019 at 4:22
  • This question has been cross-posted on AskUbuntu: askubuntu.com/questions/1115358/… Commented Feb 4, 2019 at 5:46
  • 2
    what is the issue in using sed ? Commented Feb 4, 2019 at 12:07

1 Answer 1

1

You could create a bash script that does a hexdump of your file, a simple replace and then convert back to a binary file.

You could use an application such as xxd, or hexdump to create a hex dump of your file. This is explained here: convert binary data to hex in shell script?

It looks like xxd creates a hex string that looks like this "aabbccdd" rather than your "0xaa,0xbb,0xcc,0xdd" so watch out for that!

To find out how to do a replace, you could look at this answer: Find and Replace Inside a Text File from a Bash Command

You would then want to convert the HEX string back into binary, which is explained here: linux shell scripting: hex string to bytes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.