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 6331931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:09:54+00:00 2026-05-24T18:09:54+00:00

How to find string in binary file using only read(1) ? For example I

  • 0

How to find string in binary file using only read(1) ?
For example I want to found position of string ‘abst’ in file ( without load to memory ) ?
It’s work but very primitive:

#!/usr/bin/python2
f = open("/tmp/rr", "rb")
f.seek(0)

cont = 1
while(cont):
    a1 = f.read(1)
    if a1 == 'a':
        a2 = f.read(1)
        if a2 == 'b':
            a3 = f.read(1)
            if a3 == 's':
                a4 = f.read(1)
                if a4 == 't':
                    found = True
                    cont = 0

  • 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-24T18:09:55+00:00Added an answer on May 24, 2026 at 6:09 pm

    You can find a substring by using the strings find-method.

    content = file.read()
    name = 'abst'
    if name in content:
        slice = content.find(name)
        slice = slice, slice + len(name)
    

    The read(1)-method is absolutely senseless. #see edit

    Edit: more effiecient for the memory

    def find(file, name):
        length = len(name)
        part = file.read(length)
        i = 0
        while True:
            if part == name:
                break
            char = file.read(1)
            if not char:
                return
            part = part[1:] + char
            i += 1
        return i, i + length, part
    

    I see, using read(1) isn’t that senseless.

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

Sidebar

Related Questions

I want to find whether a string contains any of the special characters like
I want to use a regex to find a particular string in my sample,
I would like to delete parts from a binary file, using C++. The binary
I'm reading in binary files normally using: //What I use to read in the
I want to be able to find a certain string which was introduced in
Using File::Find , how can I pass parameters to the function that processes each
I need to find a str[possibly n]cmp out of a hostile binary file. The
Response to : Regular Expression to find a string included between two characters while
Here at work, we often need to find a string from the list of
ABCDchinchwad18-Mar-2010-11.sql.zip ABCDsolapur18-Mar-2010-10.sql.zip How do I find the string between ABCD and the date 18-Mar-2010

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.