LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2008, 01:25 AM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Rep: Reputation: 15
Search a string recursively under one directory


I want to search a string in one file recursively under one directory. Please help.

Ravi
 
Old 07-09-2008, 02:18 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Use the -r option with grep.
 
Old 07-09-2008, 02:23 AM   #3
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Original Poster
Rep: Reputation: 15
Using Solaris 5.8. Could not find grep -r or -d recurse option :-(

Ravi
 
Old 07-09-2008, 02:29 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Then maybe this will work:
Code:
find /your/dir -type f -print0 | xargs -0 grep <string>
 
Old 07-09-2008, 02:43 AM   #5
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Original Poster
Rep: Reputation: 15
It worked. Thanks to all :-)
 
Old 07-09-2008, 04:37 AM   #6
Vinod Vellore
LQ Newbie
 
Registered: Jul 2008
Location: Chennai, India
Posts: 6

Rep: Reputation: 0
Quote:
Originally Posted by say_hi_ravi View Post
I want to search a string in one file recursively under one directory. Please help.

Ravi
Simple to remember :
# cd /home/<user-name>
# grep <string> *
This should work.
 
Old 07-09-2008, 04:47 AM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by Vinod Vellore View Post
Simple to remember :
# cd /home/<user-name>
# grep <string> *
This should work.
No, we said recursively. Your command only works for files in the home directory, not recursively.
 
  


Reply



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 09:37 AM
Search for a string within a directory hammertime1983 Linux - Newbie 2 11-01-2007 08:36 PM
recursively search basak Linux - Software 1 08-13-2006 10:25 AM
To recursively search with grep grautu Slackware 5 11-21-2005 02:53 AM
recursive search of a string in a directory ?! realos Linux - Software 4 11-27-2002 04:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:26 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
Open Source Consulting | Domain Registration