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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:01:04+00:00 2026-06-15T16:01:04+00:00

I have millions of files in a folder (nested). I need to scan a

  • 0

I have millions of files in a folder (nested). I need to scan a value from those files and print lines containing this value (say LINE_TXT). Earlier I used to sed each file but it used to take 45mins to do this. My earlier solution was something like this:

FILES=$(find $1 -type f -name 'filename.txt')
for f in $FILES
do
    if [[ "$LINE" == *LINE_TXT* ]]; then
        echo $LINE
    fi
done

I figured out that pipemill is best way to achieve this. My primary solution is something like this:

makefifo mypipe
find $1 -type f -name 'filename.txt' | xargs cat > my pipe &
while read -r LINE
do
    if [[ "$LINE" == *LINE_TXT* ]]; then
        echo $LINE
    fi
done << mypipe

Run time is 1min around. Can I improve on this further ?

  • 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-15T16:01:05+00:00Added an answer on June 15, 2026 at 4:01 pm

    Seems to me that less script overhead would make things faster.

    fgrep -r -h 'LINE_TXT' $1
    

    Just let grep do its own recursion through your directories with -r. And if you don’t want its output to include the filename in its output, include the -h option. You can pipe its output through whatever you need for post-processing.

    If you want to search only for specific filenames, grep’s -r option has options of its own: --include and --exclude, mentioned on its man page. For example:

    fgrep -h -r --include '*/filename.txt' 'LINE_TXT' $1
    

    While the find command is excellent, and invaluable in certain situations, if you can use options built in to a single tool like grep, you will incur less overhead. The find command doesn’t look inside files, so it would still have to launch grep for each one of them. If you DID want to use find, it might look something like this:

    find $1 -name 'filename.txt' -exec fgrep 'LINE_EXT' {} \;
    

    This has the benefit of giving you access to find‘s directory searching capabilities, but if all you want to do is look for a particularly named file in your directory tree, grep’s -r --include is probably sufficient and is sure to run faster.

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

Sidebar

Related Questions

I have some very large (>4 GB) files containing (millions of) fixed-length binary records.
We have millions of simple txt documents containing various data structures we extracted from
I have two 3GB text files, each file has around 80 million lines. And
I have a Windows service that is retrieving a few selected files from a
I have a small test program that creates millions of files (for testing purposes)
I have 1.2 million files split out into folders, like so: Everything ..........Folder 1
Each night I need to do work on a folder 36 days old from
I have millions of audio files , generated based on GUId ( http://en.wikipedia.org/wiki/Globally_Unique_Identifier ).
To read/write binary files, I am using DataInputStream/DataOutputStream, they have this method writeByte()/readByte(), but
Am having a folder with millions of files in the server File name will

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.