LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Search for a string (https://www.linuxquestions.org/questions/linux-newbie-8/search-for-a-string-739907/)

manjeshjk 07-14-2009 12:43 AM

Search for a string
 
Hi,

I would like to search for a particular string in a directory which contains n no of files. I don't know in which file the string is present, so the script should search for all the files that contains this string and return back the complete path of the filename.

Guys ...i require this very badly

Manjesh

jdkaye 07-14-2009 12:50 AM

If you're using kde, I know that konqueror will do this quite easily. Just go into the folder where you want to search and use Tools->Find File... then use asterisk * to indicate all files and go into the Content tab and enter your string. Konqueror will find all files containing that string.

If this is homework then that solution would not be what's required but we're not here to do your homework for you, are we? ;)
jdk

manjeshjk 07-14-2009 12:53 AM

Shell Script
 
I require this in a shell script or command line arguments. I don't access to the GUI.

PMP 07-14-2009 01:06 AM

Go in to the top level directory and run the following command

Code:

grep -r 'search_string' *
This will print the file name and what is matched, in case you want only the names of the file do

Code:

grep -rl 'search_string' *

Quads 07-14-2009 01:46 AM

Quote:

Originally Posted by manjeshjk (Post 3606842)
Hi,

I would like to search for a particular string in a directory which contains n no of files. I don't know in which file the string is present, so the script should search for all the files that contains this string and return back the complete path of the filename.

Guys ...i require this very badly

Manjesh

This is phrased like a homework question ;) Google would have found this quite easily. How are you going to learn if you don't do your homework?


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