LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find which file has a string when large number of files (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-which-file-has-a-string-when-large-number-of-files-668867/)

dwynter 09-10-2008 05:32 AM

How to find which file has a string when large number of files
 
Hi,

I have about 1000 files adding up to about 1GB in size. So performance is important. My knowledge is limited, just enough to get into trouble.

I tried running this in the current directory of the files

>for aFile in ls *.I; do awk '/aString/ { print $0 } $aFile; done;

Which I know only prints the line for where it is found, but wanted to start somewhere. But it just presents a prompt so clearly I do not understand something about the interaction between the for loop and awk.

Suggestions for the most efficient approach to achieving this?

Thanks,

David

matthewg42 09-10-2008 05:45 AM

If you just want to print the names of the files which contain some string, this will be faster than using awk:
Code:

fgrep -l aString *.I

dwynter 09-10-2008 07:06 AM

Thx, it is fast!


All times are GMT -5. The time now is 12:55 PM.