# Searching for text inside of a file using grep.



## chemistry_geek (Dec 11, 2004)

I'm trying to search for text inside all files in deep subdirectories on an external hard drive.  I've read the man page for *grep* but I still can't seem to get Panther to find the files I'm looking for.  When I place the file I eventually found on my desktop, *grep* finds the file without any problems.  Any suggestions?


----------



## ElDiabloConCaca (Dec 11, 2004)

What's the exact command you're using?

It sounds like you're not specifying the correct search path -- like you're just searching in subfolders of your home folder.


----------



## chemistry_geek (Dec 12, 2004)

This correctly finds the file when the it is on my desktop:

grep -l "0.136" /Users/chemgeek/Desktop/*.*

I have tried these and they do not find the file I needed:

grep -r "0.136" /Volumes/LaCie\ Disk/chemgeek/Documents/9-28-04/Masters_Thesis_Chemistry/Chemical_Structures/*.*

grep -l "0.136" /Volumes/LaCie\ Disk/chemgeek/Documents/9-28-04/Masters_Thesis_Chemistry/Chemical_Structures/*.*


The hard drive the files are stored on is a LaCie Big Disk Extreme 320GB.
http://www.lacie.com/products/product.htm?pid=10489


----------



## chevy (Dec 12, 2004)

did you try 
grep -lr "0.136" /Volumes/LaCie\ Disk/chemgeek/Documents/9-28-04/Masters_Thesis_Chemistry/Chemical_Structures/*.*
?


----------



## chemistry_geek (Dec 12, 2004)

yes, I tried that too; it did not work.


----------



## scruffy (Dec 12, 2004)

If you're doing a recursive search, you shouldn't need to specify *.* - in fact, I think that might only look at subdirectories that have a dot in their names.

If you specify the exact file name, rather than a globbing pattern, does it find it? what is the filename? what is its format (what if you added the -a option to make it treat binary files as text?)


----------



## chemistry_geek (Dec 14, 2004)

OK, I think I know why *grep -lr "0.136" /Volumes/LaCie\ Disk/chemgeek/Documents/9-28-04/Masters_Thesis_Chemistry/Chemical_Structures/*.** didn't find the file the day I was searching for it.  I had not yet updated the *locate database*.  After I ran the *daily* and *weekly* system maintenance cron jobs, *grep -lr "0.136" /Volumes/LaCie\ Disk/chemgeek/Documents/9-28-04/Masters_Thesis_Chemistry/Chemical_Structures/*.** found three files in less than one second, literally.

Thank you all for your help and suggestions.  I very much appreciate all the help I get from the members here.


----------



## chemistry_geek (Dec 14, 2004)

scruffy said:
			
		

> If you're doing a recursive search, you shouldn't need to specify *.* - in fact, I think that might only look at subdirectories that have a dot in their names.
> 
> If you specify the exact file name, rather than a globbing pattern, does it find it? what is the filename? what is its format (what if you added the -a option to make it treat binary files as text?)




The reason I was looking for a specific text pattern inside all of the files for my masters thesis is because I forgot the specific file name and folder(s) it could have been placed in.  I remember the the text that was in the file, that's why I was using grep.  The file I was looking for was a ChemDraw file that contains both binary and text information.  When viewed in BBEdit, I see "gibberish" characters everywhere and a few places with text that I entered to explain a chemical reaction.


----------



## profx (Dec 14, 2004)

if the volume has been indexed you can use the find feature in the finder as well. Search for content


----------



## brianleahy (Dec 14, 2004)

This works in HPUX, something similar will probably work in Darwin:


find . -type f -exec grep -l "0.136" {} \;


----------

