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

  • Home
  • SEARCH
  • 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 3695856
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:40:06+00:00 2026-05-19T04:40:06+00:00

Regards, SO I am new to python and Perl. I have been trying to

  • 0

Regards, SO

I am new to python and Perl. I have been trying to solve a simple problem and getting tied in knots with syntax. I hope someone has the time and patience to help.
I have a 25mb file in “.txt” format which contains news-wire articles going back to 1970. Each news story is concatenated to the next, with only the “Copyright” statement to delimit. Each news story starts with “Item XX of XXX DOCUMENTS”. There are certain metadata that are repeated throughout, I will use these for tagging later on.

I wish to split this 25mb file into separate .txt files, each containing one news story (i.e. the text between “DOCUMENTS” and “Copyright”, saving each with a different name (obviously).

I am trying to 1 ) open the file… 2) iterate over lines in the file checking for the eof delimiter, and if it is not present writing the line to a list 3)write that list to a seperate small file.

I’m having big problems with changing filenames using the counter, and how do I make Python start from where I left off, is the “seek” function appropriate?

so far I have been trying this approach, completely unsuccessfully:

myfile = open ("myfile.txt", 'r')
filenumber = 0
for line in myfile.readline():  
    filenumber += 1    
    w=0  
    while myfile.readline() != '\s+DOCUMENTS\s*\n'  
    ### read my line into a list  
    mysmallfile()['w'] = [myfile.readline()]  
    w += 1  
    output = open('C:\\Users\\dunner7\\Documents\###how do I change the filename      each     iteration???', 'w')  
    output.writelines(mysmallfile)   
    ###go back to start.   

Thank you for your time and patience.

RD

Here is a sample of the text file:

                           1 of 575 DOCUMENTS

                         The Washington Daybook

                            January 28, 2011

Health and Human Services Department (HHS); Food and Drug Administration (FDA)
(F.R. Page 72832) holds a meeting of the Neurological Devices Panel of the
Medical Devices Advisory Committee to discuss and make recommendations regarding
the possible reclassification of devices indicated for use in electroconvulsive
therapy, January 27-28.

TIME: 8 a.m.

LOCATION: Hilton Washington DC North/Gaithersburg, Ballroom, 620 Perry Parkway,
Gaithersburg, Md.

CONTACT: James Engles, 800-741-8138 [Note: Use the code: 3014512513, when
calling for information.]

LOAD-DATE: November 28, 2010

LANGUAGE: ENGLISH

TYPE: Meeting

       Copyright 2011 Federal Information and News Dispatch, Inc.


                           2 of 575 DOCUMENTS

                         The Washington Daybook

                            January 27, 2011

Health and Human Services Department (HHS); Food and Drug Administration (FDA)
(F.R. Page 72832) holds a meeting of the Neurological Devices Panel of the
Medical Devices Advisory Committee to discuss and make recommendations regarding
the possible reclassification of devices indicated for use in electroconvulsive
therapy, January 27-28.

TIME: 8 a.m.

LOCATION: Hilton Washington DC North/Gaithersburg, Ballroom, 620 Perry Parkway,
Gaithersburg, Md.

CONTACT: James Engles, 800-741-8138 [Note: Use the code: 3014512513, when
calling for information.]

LOAD-DATE: November 28, 2010

LANGUAGE: ENGLISH

TYPE: Meeting

       Copyright 2011 Federal Information and News Dispatch, Inc.


                           3 of 575 DOCUMENTS


                              FNS DAYBOOK

                       January 12, 2011 Wednesday
                              FUTURE EVENTS

EVENT: MEETING – HEALTH AND HUMAN SERVICES DEPARTMENT (HHS); FOOD AND DRUG
ADMINISTRATION (FDA) (F.R. PAGE 72832);
LOCATION: Hilton Washington DC North/Gaithersburg, Ballroom, 620 Perry Parkway,
Gaithersburg, Md. — January 27, 2011 8:00 am

SECTION: FEDERAL AGENCIES AND DEPARTMENTS – FUTURES

LENGTH: 72 words

SUBJECT: Health and Human Services Department (HHS); Food and Drug
Administration (FDA) (F.R. Page 72832) holds a meeting of the Neurological
Devices Panel of the Medical Devices Advisory Committee to discuss and make
recommendations regarding the possible reclassification of devices indicated for
use in electroconvulsive therapy, January 27-28.

CONTACT: James Engles, 800-741-8138 [Note: Use the code: 3014512513, when
calling for information.]

LOAD-DATE: January 10, 2011

LANGUAGE: ENGLISH

PUBLICATION-TYPE: Event Schedules

                  Copyright 2011 Federal News Service
                          All Rights Reserved
  • 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-19T04:40:07+00:00Added an answer on May 19, 2026 at 4:40 am

    Something like that:

    filenumber = 0
    outfile = None
    with open('source_file.txt') as f:
        for line in f:
            if line.strip() == 'DOCUMENTS':
                filenumber += 1
                outfile = open('result%03d.txt' % filenumber, 'w')
            elif line.strip().startswith('Copyright') and outfile:
                outfile.close()
                outfile = None
            elif outfile:
                outfile.write(line)
    if outfile:
        outfile.close()
    

    I had to guess lots of things because I don’t know exacly how the file looks like. Post the file if you have further problems.

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

Sidebar

Related Questions

No related questions found

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.