Home » Infrastructure » Unix » Search a string in a folder
Search a string in a folder [message #98222] Fri, 14 May 2004 02:39 Go to next message
Ravi
Messages: 251
Registered: June 1998
Senior Member
I am using SunOS 5.6

I want to search all files in side a folder containg a particular

string/text. folder may contain subfolders. I used grep but grep command gives only files in the current directory, It does not searches insde the subfolders. 

Thanks

 
Re: Search a string in a folder [message #98232 is a reply to message #98222] Thu, 20 May 2004 05:05 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Hi,

One can combine find and grep to search for a particular string within a directory, including the subdirectories.

Example:

find . -name *.log -exec grep -il oracle {} ;


Best regards.

Frank
Re: Search a string in a folder [message #98234 is a reply to message #98232] Thu, 20 May 2004 06:13 Go to previous messageGo to next message
Ravi
Messages: 251
Registered: June 1998
Senior Member
Thanks frank,
But I am unable to find that where is the search string in this command that i am searching for in all .log files.

Thanks
Ravi
Re: Search a string in a folder [message #98238 is a reply to message #98234] Fri, 21 May 2004 01:15 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Hi,

Please do a "man find" and "man grep". The example does a "grep" for "oracle" in the files returned by the find command (indicated by the {}).

Best regards.

Frank
Re: Search a string in a folder [message #98247 is a reply to message #98234] Wed, 26 May 2004 05:49 Go to previous message
Ravi
Messages: 251
Registered: June 1998
Senior Member
try

find [[folder_name]] -exec grep -l 'oracle' {};

it should work.
Previous Topic: using cut command
Next Topic: validation of the script in oracle when logging from shell script
Goto Forum:
  


Current Time: Thu Mar 28 19:43:49 CDT 2024