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 biv343 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
Feb 4, 2001
100
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;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top