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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:58:55+00:00 2026-05-17T17:58:55+00:00

Looking to create a hash table from a text output that looks like this

  • 0

Looking to create a hash table from a text output that looks like this (whitespace between words are tabs):

GCOLLECTOR     123456     77889     uno  
BLOCK     unique111    error     fullunique111     ...     ...     ...  
DAY     ... ... ...  
LABEL     detail     unique111     Issue     Broken - The truck broke  
LABEL     detail     unique111     Folder    3c1  
LABEL     detail     unique111     Datum     bar_1666.9  
GCOLLECTOR     234567     77889     uno  
BLOCK     unique222    error     fullunique111     ...     ...     ...  
DAY     ... ... ...  
DAY     ... ... ...
LABEL     detail     unique222     Issue     Broken - The truck broke  
LABEL     detail     unique222     Datum     bar_9921.2
LABEL     detail     unique222     Folder    6a3  
GCOLLECTOR     345678     77889     uno  
BLOCK     unique333    error     fullunique111     ...     ...     ...    
LABEL     detail     unique333     Datum     bar_7766.2
LABEL     detail     unique333     Folder    49k  
LABEL     detail     unique333     Issue     Broken - The truck broke

I would like to create a hash table that assigns each of the following to the hash:
gcollectors = Hash.new
gcollectors = { "UniqueID" => uniqueXXX,
"Datum" => bar_XXXX.X,
"FullUniqueID" => fulluniqueXXX,
"IssueGroup" => Broken
}

The uniqueXXX fields always match for the BLOCK and associated LABELs.

I am having a couple issues:
1- How do I assign just those fields to the hashes?
2- How can I split the text prior to the hyphen (in LABEL … Issue) and assign it to IssueGroup?
3- How can this be done reliably when the order of the LABEL lines is different?
.. same question for when there are multiple DAY lines or no DAY lines.

  • 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-17T17:58:55+00:00Added an answer on May 17, 2026 at 5:58 pm

    This is how I’d go about it:

    records     = [] # init an array to hold everything
    gcollectors = {} # init the hash holding info for one record
    
    # loop over the file
    File.readlines('text.txt').each do |l|
    
      # split the line into columns
      columns = l.chomp.split("\t")
    
      # if the first column is...
      case columns[0]
      when 'GCOLLECTOR'
        # we don't care about the columns, but instead use this record to tell us to
        # store the hash and reinitialize it.
        if (gcollectors.any?)
          records << gcollectors
          gcollectors = {}
        end
      when 'BLOCK'
        gcollectors['UniqueID']     = columns[1]
        gcollectors['FullUniqueID'] = columns[3]
      when 'LABEL'
        # a LABEL record could have two different values we care about so figure out
        # which it is.
        case columns[3]
        when 'Datum'
          gcollectors['Datum'] = columns[4]
        when 'Issue'
          gcollectors['IssueGroup'] = columns[4].split('-').first.strip
        end
      end
    
      # get the next record
      next
    end
    
    require 'ap'
    ap records
    # >> [
    # >>     [0] {
    # >>             "UniqueID" => "unique111",
    # >>         "FullUniqueID" => "fullunique111",
    # >>           "IssueGroup" => "Broken",
    # >>                "Datum" => "bar_1666.9"
    # >>     },
    # >>     [1] {
    # >>             "UniqueID" => "unique222",
    # >>         "FullUniqueID" => "fullunique111",
    # >>           "IssueGroup" => "Broken",
    # >>                "Datum" => "bar_9921.2"
    # >>     }
    # >> ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a hash-algorithm, to create as close to a unique hash
I'm looking to create favicon.ico files programatically from Python, but PIL only has support
I am looking to create symlinks (soft links) from Java on a Windows Vista/
If I were looking to create my own language are there any tools that
I'm writing a web app that points to external links. I'm looking to create
I'm looking create a piece of jQuery logic that answers: Are there any tables
I'm looking to create a solution for a asp.net mvc app that displays unstructured
I am looking to create a function that could create a fade-in/fade-out function on
I am looking to create a variable that is a template for repatative elements
I'm looking to create an Intellij IDEA language support plugin for Erlang. The first

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.