Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:56+00:00 2026-05-30T17:25:56+00:00

I have binary and want to extract part of it, starting from know byte

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:25:57+00:00Added an answer on May 30, 2026 at 5:25 pm

    In a single pipe:

    xxd -c1 -p file |
      awk -v b="ffd8ffd0" -v e="aaffd9" '
        found == 1 {
          print $0
          str = str $0
          if (str == e) {found = 0; exit}
          if (length(str) == length(e)) str = substr(str, 3)}
        found == 0 {
          str = str $0
          if (str == b) {found = 1; print str; str = ""}
          if (length(str) == length(b)) str = substr(str, 3)}
        END{ exit found }' |
      xxd -r -p > new_file
    test ${PIPESTATUS[1]} -eq 0 || rm new_file
    

    The idea is to use awk between two xxd to select the part of the file that is needed. Once the 1st pattern is found, awk prints 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 END part of the awk script, which return a non-zero exit status. This is catch by bash‘s ${PIPESTATUS[1]} where I decided to delete the new file.

    Note that en empty file also mean that nothing has been found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a binary that I want to convert to standard MIME-compliant base64 string.
I have a binary string as follows: String bin = 1101; and I want
How can I extract information from a binary file that I don't have the
I have a binary file to which I want to append a chunk of
I have one binary file and I want to read this file like first
Say I have a binary file of 12GB and I want to slice 8GB
I have a binary tree where each node can have a value. I want
I have a Binary tree for a mathematical expression(infix), i want to convert directly
I am writing some Natural Language Processing code and want to have a binary
I want to create a Binary file of my project. I have set my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.