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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:14:05+00:00 2026-06-18T10:14:05+00:00

I am trying to parse certain paragraphs out of a text file. The paragraph

  • 0

I am trying to parse certain paragraphs out of a text file. The paragraph I am trying to parse is labeled as so:

ABST

PAL An abrasion-resistant laminate is prepared by providing an ultra thin
coating of mineral particles and micro crystalline cellulose on the
surface of conventional printed paper, followed by impregnating the paper
with a conventional laminating resin, and then using the print paper so
obtained in a laminating process without the necessity of using an overlay
sheet.

PARN

So far all I have gotten is:

with open('file.txt', 'r+') as f:
   for line in f:
        if line.startswith("ABST"):
            print f.next()

This is only leaving me with the first line of the paragraph. What I would like to is something along the lines of:

with open('file.txt', 'r+') as f:
   for line in f:
        if line.startswith("ABST"):
            *print lines until next header*

I realize this is not too complicated but I have been stuck in a rut so any suggestion will help.

  • 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-18T10:14:06+00:00Added an answer on June 18, 2026 at 10:14 am
    with open('file.txt', 'r+') as f:
       flag = False
       for line in f:
            if line.startswith("PARN"):
                flag = False
            if flag:
                print line
            if line.startswith("ABST"):
                flag = True
    

    Should do the trick… Straight and to the point. In any case, you can let the loop handle the iteration for you, just make sure you remember if you should print or not.

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

Sidebar

Related Questions

I'm trying to parse through an mht (text) file and extract just certain lines.
I'm new to PHP and am trying to parse certain text from a txt
What I'm trying to do is parse certain text from a webpage that is
I'm trying to parse some simple JSON data and pull out certain parts to
I have been trying to parse for this certain piece of text in a
I'm trying to parse out an complex XML file using LINQ. The files contains
I've been trying to get the comments out of a certain .php file on
I'm trying to use JSoup in my android app to parse a certain website.
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>
Trying to parse an HTML document and extract some elements (any links to text

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.