I have binary and want to extract part of it, starting from know byte string (i.e. FF D8 FF D0) and ending with known byte string (AF FF D9)
In the past I’ve used dd to cut part of binary file from beginning/ending but this command doesn’t seem to support what I ask.
What tool on terminal can do this?
In a single pipe:
The idea is to use
awkbetween twoxxdto select the part of the file that is needed. Once the 1st pattern is found,awkprints the bytes until the 2nd pattern is found and exit.The case where the 1st pattern is found but the 2nd is not must be taken into account. It is done in the
ENDpart of theawkscript, which return a non-zero exit status. This is catch bybash‘s${PIPESTATUS[1]}where I decided to delete the new file.Note that en empty file also mean that nothing has been found.