Searching for text inside of a file using grep.

chemistry_geek

Registered
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?
 
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.
 
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
 
did you try
grep -lr "0.136" /Volumes/LaCie\ Disk/chemgeek/Documents/9-28-04/Masters_Thesis_Chemistry/Chemical_Structures/*.*
?
 
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?)
 
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.
 
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.
 
if the volume has been indexed you can use the find feature in the finder as well. Search for content
 
This works in HPUX, something similar will probably work in Darwin:


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