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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:03:59+00:00 2026-05-29T06:03:59+00:00

I have a very complex parsing problem. Any thoughts would be appreciated here. I

  • 0

I have a very complex parsing problem. Any thoughts would be appreciated here. I have a test.dat file.The file to be parsed looks like this:

*   Number                  =              40

Time =  0
  1   10.13   10   10.11   12   13
  .
  .

Time =  n
  1   10   10   10   12.50   13
  .
  .

There are N time blocks and each block has 40 lines like shown above. What I would like to do is add e.g. the 1st line of first block , then 1st line in block #2 .. and so on to to a new file -test_1.dat. Similarly, 2nd line of every block to test_2.datand so on.The lines in the block should be written as is to the new _n.dat file. Is there any way to do this? The number I have assumed here is 40, so if the * number = 40 there will be 40 lines under each time block.

regards,
Ris

  • 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-29T06:03:59+00:00Added an answer on May 29, 2026 at 6:03 am

    You can read the file in as a list of strings (call it fileList), where each string is a different line:

    f = open('filename')
    fileList = f.readlines()
    

    Then, remove the “header” part of your file with

    fileList.pop(0)
    fileList.pop(0)
    

    Then, do

    outFileContents = {} # This will be a dict, where number -> content of test_number.dat
    for outFileName in range(1,41): #outFileName will be the number going after the _ in your filename
        outFileContents[outFileName] = []
        for n in range(40): # Counting through the time blocks
            currentRowIndex = (42 * n) + outFileName # 42 to account for the Time = and blank row
            outFileContents[outFileName].append(fileList[currentRowIndex])
    

    Finally you can loop through outFileContents and write the contents of each value to separate files.

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

Sidebar

Related Questions

I've worked on projects that have very complex XML configuration, and one problem that's
I have a very complex controller with a very complex set of views and
I have a very complex web app project I want to re-structure. Naturally, it
I have an idea for a web-based service. The implementation is very complex. There
We have very strange problem, one of our applications is continually querying server by
i have very simple problem. I need to create model, that represent element of
I have a very complex system (100+ threads) which need to send email without
I have a very complex Linq to SQL query that returns a result set
I have a very complex task - create a software that imports XMl files
I have a very complex cross-platform application. Recently my team and I have been

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.