0

so I'd like to remove parts within (NOT at beginning or the end, or I would have used dd) a binary file, when I encounter a certain binary string value. ie :

  • if FF FB FF FB A4 is found, remove 2048 bytes before the second FF FB here (meaning the first FF FB is deleted as well as the 2046 bytes preceeding it)

repeat till the end of the file.(no need to test/prevent "eating itself", range between that string occurences always much larger than 2048)

how can I do that in bash ? thanks in advance

1 Answer 1

1

You can use grep to locate the "FF FB FF FB A4", then use dd to cut file:

pos=$(grep --only-matching --byte-offset --binary --text --perl-regexp "\xFF\xFB\xFF\xFB\xA4" filename|head -1|cut -d ':' -f1)

It will tell you where the string.

dd if=filename of=output bs=1 ibs=1 count=$pos

This get the leading part. I think you know how to deal with left staff

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.