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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:42:49+00:00 2026-06-12T16:42:49+00:00

I have a plain text table like this . I need to group the

  • 0

I have a plain text table like this. I need to group the result line so that the data is together in their respective columns.

I can split the string (one line) on a space and then I will get an array like:

["2", "1/47", "M4044", "25:03*", "856", "12:22", "12:41", "17.52", "Some", "Name", "Yo", "Prairie", "Inn", "Harriers", "Runni", "25:03"]

I can also split on two spaces, which gets me close, but still inconsistent, as you see with the name:

["2", " 1/47", "M4044", " 25:03*", "856", " 12:22", " 12:41", "17.52 Some Name Yo", "", "", "", "", "", "", "Prairie Inn Harriers Runni", " 25:03 "]

I can specify which indexes to join on, but I need to grab possibly thousands of files just like this, and the columns are not always going to be in the same order.

The one constant is that the column data is never longer than the divider between column name and data (the ====). I tried to use this to my advantage, but found some loopholes.

I need to write an algorithm to detect what stays in the name column and what stays in whatever other ‘word’ columns. Any thoughts?

  • 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-12T16:42:50+00:00Added an answer on June 12, 2026 at 4:42 pm

    First we set up the problem:

    data = <<EOF
    Place Div/Tot Div   Guntime  PerF 1sthalf 2ndhalf 100m   Name                      Club                       Nettime 
    ===== ======= ===== =======  ==== ======= ======= ====== ========================= ========================== ======= 
        1   1/24  M3034   24:46   866   12:11   12:35  15.88 Andy Bas                  Prairie Inn Harriers         24:46 
        2   1/47  M4044   25:03*  856   12:22   12:41  17.52 Some Name Yo              Prairie Inn Harriers Runni   25:03 
    EOF
    lines = data.split "\n"
    

    I like to make a format string for String#unpack:

    format = lines[1].scan(/(=+)(\s+)/).map{|f, s| "A#{f.size}" + 'x' * s.size}.join
    #=> A5xA7xA5xA7xxA4xA7xA7xA6xA25xA26xA7x
    

    The rest is easy:

    headers = lines[0].unpack format
    lines[2..-1].each do |line|
      puts Hash[headers.zip line.unpack(format).map(&:strip)]
    end
    #=> {"Place"=>"1", "Div/Tot"=>"1/24", "Div"=>"M3034", "Guntime"=>"24:46", "PerF"=>"866", "1sthalf"=>"12:11", "2ndhalf"=>"12:35", "100m"=>"15.88", "Name"=>"Andy Bas", "Club"=>"Prairie Inn Harriers", "Nettime"=>"24:46"}
    #=> {"Place"=>"2", "Div/Tot"=>"1/47", "Div"=>"M4044", "Guntime"=>"25:03", "PerF"=>"856", "1sthalf"=>"12:22", "2ndhalf"=>"12:41", "100m"=>"17.52", "Name"=>"Some Name Yo", "Club"=>"Prairie Inn Harriers Runni", "Nettime"=>"25:03"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 40000 records in that table that contains plain text and within
Suppose I have something like this: if ($command === 'txt') { header('Content-type: text/plain;charset=utf-8'); echo
I have a plain text file that I need to read in using C#,
I have a SQlite3 table that has typeless columns like in this example: CREATE
I have a webpage that is transferring A stylesheet as a text/plain MIME type.
I have a plain table view that is laying out properly except that the
I have an HTML table element, with rows containing not only plain-text characters, but
I have table with a XML column (called MetaData) which looks like this: <props>
I have a data like this: Re: Building A Month kWh 1 100 2
I have stored page contents (tables, plain text, images and paragraphs) into a variable.

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.