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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:39:23+00:00 2026-05-25T19:39:23+00:00

I need a fast way to match a value in AWK, I have 250k

  • 0

I need a fast way to match a value in AWK, I have 250k values to search.

I’m doing something like this:

    #list with 250k numbers instead of four
    number_list="9998532001 9998536052 9998543213 9998544904"

    if ( index(number_list,substr($5,9)) ) 
         {printf "Value: %s\n",$5;}

Any suggestions for a faster search ?

  • 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-25T19:39:24+00:00Added an answer on May 25, 2026 at 7:39 pm

    If the substring you are searching for is of a consistent length and position in the target string (say the last 6 digits), then you could preprocess the list into an array and you’d be good to go.

    Preprocessing step (perhaps in the BEGIN target)

    n=split(numbers_list,a," "); # Rip in input sting into pieces
    for ( num in a ) {
        key=substr(a[num],length(a[num])-6,6);  # Get the last six digits
    
        # Error processing (i.e. collision handling) should go here 
    
        list[key]=a[num];
    }
    

    Then when you need to do the lookup

    i=list[substr($5,9)]   # i is now the full number associated with the key
    

    This is only a win if you will do many lookups, because you still have to pay the cost of iterating through that whole list (twice, in fact) during the pre-processing.


    Note that exact matching to the whole number qualifies as a substring of known length and position, just use key=a[num] (which looks funny and leads to several simplifications of the above code, but I’m sure you can figure it out).


    If you are looking for any occurrence of substring($5,9) in any of the numbers, this won’t work, you’ll have to iterate through n every time.

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

Sidebar

Related Questions

I need a very fast SQLite database acces. Setting parameters this way: PRAGMA synchronize
Hi so I need some FAST way to search for a word in a
I need a fast way to count the number of bits in an integer
I'm working with Android and I really need a fast way to get a
I need to check in some fast way if there is any text nodes
Need a way to allow sorting except for last item with in a list.
I need a fast way in C# leanguage of converting/casting array of bytes encoding
I need a fast way to extract data from json responses a I get
(Briefly, like this question but for Windows servers.) I have several Win2003 servers running
I need a very fast way of displaying a data buffer to screen. I

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.