LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-14-2009, 01:43 AM   #1
manjeshjk
LQ Newbie
 
Registered: Dec 2008
Location: Bangalore
Posts: 6

Rep: Reputation: 0
Unhappy 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
 
Old 07-14-2009, 01:50 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
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
 
Old 07-14-2009, 01:53 AM   #3
manjeshjk
LQ Newbie
 
Registered: Dec 2008
Location: Bangalore
Posts: 6

Original Poster
Rep: Reputation: 0
Shell Script

I require this in a shell script or command line arguments. I don't access to the GUI.
 
Old 07-14-2009, 02:06 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
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' *
 
Old 07-14-2009, 02:46 AM   #5
Quads
Member
 
Registered: Jul 2008
Location: Indiana
Distribution: Fedora, Ubuntu, Slackware
Posts: 203

Rep: Reputation: 34
Quote:
Originally Posted by manjeshjk View Post
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 10:37 AM
C....Search a string for a string Scrag Programming 4 06-14-2004 05:15 PM
[c++] Search in a string hylke Programming 5 06-14-2004 12:20 PM
string search in C h/w Programming 17 10-13-2003 07:26 PM
Search for a string TheOriginalH Linux - General 5 09-24-2003 11:48 AM


All times are GMT -5. The time now is 01:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration