Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Text

Status
Not open for further replies.

swaroop

Programmer
Joined
Feb 4, 2001
Messages
100
Location
US
How can I search a given text in files under current and sub directories?

I wanted to find a text(ex: "cafe/images/Aug-27_BEIGE.gif") in the files under 'current and sub' directories if any file contains this text display it.

Thanks in advance.

Swaroop.
 
PATTERN="cafe/images/Aug-27_BEIGE.gif"
DIR="mydir"
LIST=`grep $PATTERN \`find $DIR -type f\``

LIST will contain the file and the line containing the test separted by a colon. Here's an example:

./mydir/subdir1/joe:<a href=/pictures/cage/images/Aug-27_BEIGE.fit&quot;>MY PICTURE</a>

 
This is what I use:

cd <dir>
find . -print | xargs grep &quot;mystring&quot;
 
The GNU grep has a convenient --recursive option to do this.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top