Replace hex in binary file with shell without sed












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?



Thanks










share|improve this question























  • You might want to clarify your requirements. For example, sed is a standard part of Ubuntu and, for that matter, all POSIX systems. How is it that you have an Ubuntu system that doesn't have sed? Answering that question might help us understand what tools you do have available.

    – John1024
    Feb 3 at 21:46











  • Perhaps it's a requirement of the script and not that OPs lacks the sed tool!

    – George Udosen
    Feb 3 at 22:29






  • 1





    Probably tr is more appropriate than (line-base) sed anyhow - another option would be perl (which has its own tr and may be invoked in "slurp mode")

    – steeldriver
    Feb 3 at 22:37
















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?



Thanks










share|improve this question























  • You might want to clarify your requirements. For example, sed is a standard part of Ubuntu and, for that matter, all POSIX systems. How is it that you have an Ubuntu system that doesn't have sed? Answering that question might help us understand what tools you do have available.

    – John1024
    Feb 3 at 21:46











  • Perhaps it's a requirement of the script and not that OPs lacks the sed tool!

    – George Udosen
    Feb 3 at 22:29






  • 1





    Probably tr is more appropriate than (line-base) sed anyhow - another option would be perl (which has its own tr and may be invoked in "slurp mode")

    – steeldriver
    Feb 3 at 22:37














0












0








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?



Thanks










share|improve this question














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?



Thanks







scripts sed sh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 3 at 21:03









g319909.nwytg.coMg319909.nwytg.coM

1




1













  • You might want to clarify your requirements. For example, sed is a standard part of Ubuntu and, for that matter, all POSIX systems. How is it that you have an Ubuntu system that doesn't have sed? Answering that question might help us understand what tools you do have available.

    – John1024
    Feb 3 at 21:46











  • Perhaps it's a requirement of the script and not that OPs lacks the sed tool!

    – George Udosen
    Feb 3 at 22:29






  • 1





    Probably tr is more appropriate than (line-base) sed anyhow - another option would be perl (which has its own tr and may be invoked in "slurp mode")

    – steeldriver
    Feb 3 at 22:37



















  • You might want to clarify your requirements. For example, sed is a standard part of Ubuntu and, for that matter, all POSIX systems. How is it that you have an Ubuntu system that doesn't have sed? Answering that question might help us understand what tools you do have available.

    – John1024
    Feb 3 at 21:46











  • Perhaps it's a requirement of the script and not that OPs lacks the sed tool!

    – George Udosen
    Feb 3 at 22:29






  • 1





    Probably tr is more appropriate than (line-base) sed anyhow - another option would be perl (which has its own tr and may be invoked in "slurp mode")

    – steeldriver
    Feb 3 at 22:37

















You might want to clarify your requirements. For example, sed is a standard part of Ubuntu and, for that matter, all POSIX systems. How is it that you have an Ubuntu system that doesn't have sed? Answering that question might help us understand what tools you do have available.

– John1024
Feb 3 at 21:46





You might want to clarify your requirements. For example, sed is a standard part of Ubuntu and, for that matter, all POSIX systems. How is it that you have an Ubuntu system that doesn't have sed? Answering that question might help us understand what tools you do have available.

– John1024
Feb 3 at 21:46













Perhaps it's a requirement of the script and not that OPs lacks the sed tool!

– George Udosen
Feb 3 at 22:29





Perhaps it's a requirement of the script and not that OPs lacks the sed tool!

– George Udosen
Feb 3 at 22:29




1




1





Probably tr is more appropriate than (line-base) sed anyhow - another option would be perl (which has its own tr and may be invoked in "slurp mode")

– steeldriver
Feb 3 at 22:37





Probably tr is more appropriate than (line-base) sed anyhow - another option would be perl (which has its own tr and may be invoked in "slurp mode")

– steeldriver
Feb 3 at 22:37










1 Answer
1






active

oldest

votes


















0














Perhaps bash indexed arrays would help:



#!/usr/bin/env bash
set -e

my_hex=(0xaa 0xbb 0xcc 0xdd)
my_new_hex=(0x11 0x22 0x33 0x44)

# exchange values
for i in $(seq 1 "${#my_hex[@]}")
do
my_hex["$i" - 1]=${my_new_hex[$i - 1]}
echo "${my_hex[$i - 1]}"
done





share|improve this answer


























  • Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

    – Sergiy Kolodyazhnyy
    Feb 3 at 22:40











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1115358%2freplace-hex-in-binary-file-with-shell-without-sed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Perhaps bash indexed arrays would help:



#!/usr/bin/env bash
set -e

my_hex=(0xaa 0xbb 0xcc 0xdd)
my_new_hex=(0x11 0x22 0x33 0x44)

# exchange values
for i in $(seq 1 "${#my_hex[@]}")
do
my_hex["$i" - 1]=${my_new_hex[$i - 1]}
echo "${my_hex[$i - 1]}"
done





share|improve this answer


























  • Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

    – Sergiy Kolodyazhnyy
    Feb 3 at 22:40
















0














Perhaps bash indexed arrays would help:



#!/usr/bin/env bash
set -e

my_hex=(0xaa 0xbb 0xcc 0xdd)
my_new_hex=(0x11 0x22 0x33 0x44)

# exchange values
for i in $(seq 1 "${#my_hex[@]}")
do
my_hex["$i" - 1]=${my_new_hex[$i - 1]}
echo "${my_hex[$i - 1]}"
done





share|improve this answer


























  • Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

    – Sergiy Kolodyazhnyy
    Feb 3 at 22:40














0












0








0







Perhaps bash indexed arrays would help:



#!/usr/bin/env bash
set -e

my_hex=(0xaa 0xbb 0xcc 0xdd)
my_new_hex=(0x11 0x22 0x33 0x44)

# exchange values
for i in $(seq 1 "${#my_hex[@]}")
do
my_hex["$i" - 1]=${my_new_hex[$i - 1]}
echo "${my_hex[$i - 1]}"
done





share|improve this answer















Perhaps bash indexed arrays would help:



#!/usr/bin/env bash
set -e

my_hex=(0xaa 0xbb 0xcc 0xdd)
my_new_hex=(0x11 0x22 0x33 0x44)

# exchange values
for i in $(seq 1 "${#my_hex[@]}")
do
my_hex["$i" - 1]=${my_new_hex[$i - 1]}
echo "${my_hex[$i - 1]}"
done






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 3 at 22:32

























answered Feb 3 at 22:27









George UdosenGeorge Udosen

21.2k94570




21.2k94570













  • Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

    – Sergiy Kolodyazhnyy
    Feb 3 at 22:40



















  • Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

    – Sergiy Kolodyazhnyy
    Feb 3 at 22:40

















Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

– Sergiy Kolodyazhnyy
Feb 3 at 22:40





Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays

– Sergiy Kolodyazhnyy
Feb 3 at 22:40


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1115358%2freplace-hex-in-binary-file-with-shell-without-sed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

Is this a new Fibonacci Identity?

19世紀