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.
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:
Edit: commented out some lines and made a couple of other changes.
If there is a large number of files, then the
forcould fail and you should use awhileloop with afindpiped 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: