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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:00:51+00:00 2026-06-03T15:00:51+00:00

I have a text file that looks like this: STUFF UP HERE APEXED NUMBER

  • 0

I have a text file that looks like this:

STUFF UP HERE

APEXED NUMBER : 123456789

1234567   Bob,Hope E.                   123.12              
1234567   TOM ROGERS JR III             123.18                
1234567   NICE, JOHNATH               4,450.00                 
1234567   PERDOND, DELLA              4,762.00               
1234567   ERICCY, PHIL                4,552.00               


  STUFF IN BETWEEN




APEXED NUMBER :

1234567   RICHARDSON,FELICIA D          632.00     
1234567   EARLEY, RICKY L               140.00     

STUFF ON THE BOTTOM

I want to read the file and find the words “APEXED NUMBER :” Then I want to determine if there are numbers after the colon. For example after the first APEXED NUMBER : the numbers 123456789 appear. I want to save this number. Then I want the file to skip a line and read the numbers and information after – assigning the information to different variables.

Then I want to continue through the file (line by line) until I find another “APEXED NUMBER” text and check if there are numbers after it – if there are not I want to assign these APEX NUMBER a value of “unknown” and move on.

Then take all the text found and store in an array separated by commas.

Here is my current attempt:

def is_numeric?(object)  #used to determine if a number is a number
true if Float(object) rescue false 
end

def is_apexed_line?(object)   # check if text has "APEXED NUMBER :"
true if object == "APEXED NUMBER :" rescue false
end

def load_file
 raw_records = []
 infile = File.open("test.txt", "r") 
 while line = infile.gets
 possible_apexed_line = line[2,15]

 if is_apexed_line?(possible_apexed_line)
 apexed_line = line[2,15]
 possible_apexed_number_present = line[18,9]

 if is_numeric?(possible_apexed_number_present)  
  abc_apexed_number = line[18,9]
  else abc_apexed_number = "unknown"
  end  # end of if


record = [apexed_line, abc_apexed_number]
raw_records << record

end  # end of if

end

puts raw_records.map {|record| record*','}


 infile.close

end

load_file

This produces:

APEXED NUMBER :, 123456789
APEXED NUMBER :, unknown

But this is as far as my learning thus far will take me. The result I am looking for is this:

1234567, BOB, HOPE E., 123.12, APEXED NUMBER :, 123456789
1234567, TOM ROGERS JR III, 123.18 , APEXED NUMBER :, 123456789              
1234567, NICE, JOHNATH,  4450.00  ,APEXED NUMBER :, 123456789               
1234567, PERDOND, DELLA, 4762.00 , APEXED NUMBER :, 123456789              
1234567, ERICCY, PHIL, 4552.00, APEXED NUMBER :, 123456789
1234567,   RICHARDSON,FELICIA D, 632.00 ,  APEXED NUMBER :, unknown  
1234567,   EARLEY, RICKY L, 140.00 , APEXED NUMBER :, unknown

Any suggestions/help to point me in the right direction will be appreciated. I am not wedded to this approach. If there are other ways to do it please suggest… I am learning ruby so I would prefer ruby suggestions.

Thanks

  • 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-03T15:00:53+00:00Added an answer on June 3, 2026 at 3:00 pm

    Here’s mine:

    File.open(filename).each_line do |line|
        @apexed_number = ('' == $1) ? 'unknown' : $1 if line =~ /APEXED NUMBER :\s*(\d*)/
        puts [$1,$2,$3,@apexed_number].join(', ') if line =~ /(\d+)\s{2,}(.*?)\s{2,}([\d,.]+)/
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks like this: value1 value2 value3 There are
I have a text file that looks like this: 1,Smith, 249.24, 6/10/2010 2,Johnson, 1332.23,
Suppose I have a text file that looks like this: 33 3 46 12
I have a text file that looks like this: gene1 gene2 gene3 a d
I have text in a file that looks like this: text1 5,000 6,000 text2
I have a text file that looks something like this where the first column
I have a chatlog file that looks like this (name represents screenames and text
So I have a text file called maze.txt that looks like this: ############### Sacbifnsdfweovw
I have an XML file that looks like this <comments> <text> <![CDATA[ <!--cached-Tue, 02
I have a text file that looks a bit like: random text random 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.