Replace hex in binary file with shell without sed
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
add a comment |
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
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 havesed
? 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
Probablytr
is more appropriate than (line-base)sed
anyhow - another option would beperl
(which has its owntr
and may be invoked in "slurp mode")
– steeldriver
Feb 3 at 22:37
add a comment |
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
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
scripts sed sh
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 havesed
? 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
Probablytr
is more appropriate than (line-base)sed
anyhow - another option would beperl
(which has its owntr
and may be invoked in "slurp mode")
– steeldriver
Feb 3 at 22:37
add a comment |
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 havesed
? 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
Probablytr
is more appropriate than (line-base)sed
anyhow - another option would beperl
(which has its owntr
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
add a comment |
1 Answer
1
active
oldest
votes
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
Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays
– Sergiy Kolodyazhnyy
Feb 3 at 22:40
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays
– Sergiy Kolodyazhnyy
Feb 3 at 22:40
add a comment |
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
Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays
– Sergiy Kolodyazhnyy
Feb 3 at 22:40
add a comment |
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
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
edited Feb 3 at 22:32
answered Feb 3 at 22:27
George UdosenGeorge Udosen
21.4k94570
21.4k94570
Suggestion for improvement: linuxjournal.com/content/bash-associative-arrays
– Sergiy Kolodyazhnyy
Feb 3 at 22:40
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 havesed
? 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 beperl
(which has its owntr
and may be invoked in "slurp mode")– steeldriver
Feb 3 at 22:37