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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:02:09+00:00 2026-06-09T07:02:09+00:00

I have checked and played with various examples and it appears that my problem

  • 0

I have checked and played with various examples and it appears that my problem is a bit more complex than what I have been able to find. What I need to do is search for a particular string and then delete the following line and keep deleting lines until another string is found. So an example would be the following:

a
b
color [
0 0 0,
1 1 1,
3 3 3,
] #color
y
z

Here, "color [" is match1, and "] #color" is match2. So then what is desired is the following:

a
b
color [
] #color
y
z
  • 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-06-09T07:02:22+00:00Added an answer on June 9, 2026 at 7:02 am

    This “simple to follow” code example will get you started .. you can tweak it as needed. Note that it processes the file line-by-line, so this will work with any size file.

    start_marker = 'startdel'
    end_marker = 'enddel'
    
    with open('data.txt') as inf:
        ignoreLines = False
        for line in inf:
            if start_marker in line:
                print line,
                ignoreLines = True
            if end_marker in line:
                ignoreLines = False            
            if not ignoreLines:
                print line,
    

    It uses startdel and enddel as “markers” for starting and ending the ignoring of data.

    Update:

    Modified code based on a request in the comments, this will now include/print the lines that contain the “markers”.

    Given this input data (borrowed from @drewk):

    Beginning of the file...
    stuff
    startdel
       delete this line
       delete this line also
    enddel
    stuff as well
    the rest of the file...  
    

    it yields:

    Beginning of the file...
    stuff
    startdel
    enddel
    stuff as well
    the rest of the file...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that is and has been perplexing me for hours. I
I have checked this similar question, but the suggestions did not solve my problem:
I have checked few other posts and found some UIAnimation transitions that kind-of give
I have checked out now a local working copy of a codebase that lives
I have checked the assembler options of GNU assembler as and I didn't find
I have a very peculiar problem. I understand that while in the foreground the
I have simple WinForms GUI that I want to use with TabPages. The problem
I have checked many questions here but none has my answer. I appreciate if
I have checked with Aweber customers service and they told me their internal function
I have checked a lot of questions on stackoverflow and I seem to have

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.