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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:57:57+00:00 2026-06-07T20:57:57+00:00

I am writing an awk script wherin I want to search for some strings

  • 0

I am writing an awk script wherin I want to search for some strings in a file.The problem I am facing is …

The file is extremely huge, in the sense .. Around 1 million lines .

If I search for a string which is present at the last line of the file, then I have unnecessarily traversed the rest of the beginning lines and hence I am looking for some command which when I give the string as an argument, it should give me the line number of the file .. Or I would like to do a binary search on the file, any redirection regarding this .

Just an additional note, the string is not a single string, I have multiple strings to search at one point of time

  • 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-07T20:58:00+00:00Added an answer on June 7, 2026 at 8:58 pm

    Regardless of what you do, if the data is in a file, it will have to be read into memory before you can do any processing (no matter how efficient), sorting, searching, etc.

    Are you running out of memory, or are you concerned about time? If memory isn’t an issue, 1 million records don’t seem that big these days.

    If you just want to determine if a certain string is present in your data file, you could try use grep. E.g.,

     grep -n target_string data.txt
    

    will print the line and line number if the target was found in the file. More information on the grep man page.

    If you want to locate and then process a line in the file, then grep won’t work, and you’ll have to use awk (like you mentioned), or look at sed or writing a custom script in Python or some other language. In all cases, the file will have to be read one way or the other.

    Perhaps breaking the file into chunks and then processing a specific part (if you can determine ahead of time where to search – though that sound unlikely from your question)

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

Sidebar

Related Questions

I'm writing a shell script that outputs all untranslated strings from gettext .po file,
I am writing a awk script that takes some columns of input in a
Writing a shell script that pretty much wraps around an Awk script. I'd like
at the moment I'm writing a simple script in ksh who should take some
I want to select some columns in a file and run some command on
I am currently writing an awk script within a bash script. One of my
I am writing a bash script that modifies a file that looks like this:
I am writing an awk script that will take the output of grep and
I'm writing a shell script that opens a file and needs to find a
I'm currently writing a simple .sh script to parse an Exim log file for

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.