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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:40:06+00:00 2026-05-13T09:40:06+00:00

I was using the return value of fgrep -s ‘text’ /folder/*.txt to find if

  • 0

I was using the return value of fgrep -s 'text' /folder/*.txt to find if ‘text’ is in any .txt file in /folder/. It works, but I find it too slow for what I need, like if it searches for ‘text’ in all the files before giving me an answer.

I need something that quickly gives me a yes/no answer when it finds at least one file with the ‘text’. Probably some awk script.

  • 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-13T09:40:06+00:00Added an answer on May 13, 2026 at 9:40 am

    You can use this to shorten your search if it’s the kind that would be based on mopoke’s answer. This stops after the first match in the first file in which it’s found:

    # found=$(false)
    found=1    # false
    text="text"
    for file in /folder/*.txt
    do
        if fgrep -m1 "$text" "$file" > /dev/null
        then
            found=$?
            # echo "$text found in $file"
            break
        fi
    done
    # if [[ ! $found ]]
    # then
    #    echo "$text not found"
    # fi
    echo $found # or use exit $found
    

    Edit: commented out some lines and made a couple of other changes.

    If there is a large number of files, then the for could fail and you should use a while loop with a find piped into it.

    If all you want to do is find out whether there is any .txt file in a folder regardless of the file’s contents, then use something like this all by itself:

    find /folder -name "*.txt"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this: jQuery.validator.addMethod(regex2, function(value, element, param) { return value.match(new RegExp(. + param +
I am using RestEasy to marchal entities to JSON. That works okay but somehow
I get a different return value each time, so I'm doing something wrong. If
I'm looking for a way to get the return value of a method via
How can I reverse a predicate's return value, and remove the elements that return
I know you can assign a function's return value to a variable and use
The following program shows that we can use return or pthread_exit to return a
I am using Microsoft Visual C++ 2010. If I have a function like this:
I have to request data for a JS-script from a MySQL database (based upon
Here's a skeleton Makefile just to make it easier to describe the problem: all_tests

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.