Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
Does anyone know of a utility (like FileLocator Pro for Windows) that will do a low-level file search using a regex expression? Spotlight can't do it.

The closest I can come to is EasyFind, but it doesn't have the full RegEx capability. Using a RegEx, it misses most of the files it should find. (But, hey, it's free and works really well most of the time.)

I routinely have to go to 'doze to do these file searches. I've tried every search tool out there, but I can't find a single one that will really do the trick.

Some of the search programs, like HoudaSpot, use the Spotlight index so they simply won't work for searching quasi-binary files that come from another OS.

Look forward to any suggestions.

Thanks,

- m
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
I just use find at the CLI when I need that. Try the -regex or -iregex switches.

I'm not a UNIX expert, so I'm not sure, given that I'm trying to regex search inside the binary files and not just doing an "ls -la" or similar (to search only for file names) how I would do a binary internal file search.

Do you have a command I could use as a starting point?

Say I have a directory /temp and it has a mix of different types of (non-Spotlight-indexed) binary files. I would like to be able to write a regex that would search every file's contents in that directory and then give me a list of the files (and possibly some matching surrounding text).

Appreciate your reply.

Thanks,

- m
 
  • Like
Reactions: grahamperrin

grahamperrin

macrumors 601
Jun 8, 2007
4,942
648
DEVONtechnologies EasyFind might be of interest. http://www.devontechnologies.com/products/freeware/

… Say I have a directory /temp and it has a mix of different types of (non-Spotlight-indexed) binary files. I would like to be able to write a regex that would search every file's contents in that directory and then give me a list of the files (and possibly some matching surrounding text). …

sudo grep -R -C 2 -i soughtpattern /temp

I'm no expert. You'll find good answers in Stack Exchange, http://stackoverflow.com/a/9083/38108 and so on.
 

skinned66

macrumors 65816
Feb 11, 2011
1,373
1,225
Ottawa, Canada
I'm not a UNIX expert, so I'm not sure, given that I'm trying to regex search inside the binary files and not just doing an "ls -la" or similar (to search only for file names) how I would do a binary internal file search.

Do you have a command I could use as a starting point?

Say I have a directory /temp and it has a mix of different types of (non-Spotlight-indexed) binary files. I would like to be able to write a regex that would search every file's contents in that directory and then give me a list of the files (and possibly some matching surrounding text).

Appreciate your reply.

Thanks,

- m
Ah, I misunderstood the original question - for contents. My apologies.

grep will do this.

sudo grep -R -E <pattern> <dir>/*

where -R means recursive search
<dir> can be any directory and * means all directory contents (only include -R if you want to all enter subdirectories.)

the "sudo" is only necessary for protected files and directories - i.e. "Permission Denied" without it. For your own personal documents it's not necessary.

Here's a quick example slapped together. I made a directory called "test" and a subdirectory called "mysubdir" with a file called "myfile.txt" in it containing the word "hello".


computername:test skinned$ grep -R -E "(?i:hElLo)" *
mysubdir/myfile.txt:hello! ...MATCH(ES) - 1 per line

computername:test skinned$ ...Search completed

You can also dump the results to a file:

grep -R -E "(?i:hElLo)" * > /Users/skinned/Desktop/result.txt

So your example would look something like

cd /temp
grep -E "<pattern>" *
or
grep -E "<pattern>" /temp/*

to search all files in /temp only.

You can safely abort any of these searches at any time by pressing Control+C.


I understand that a GUI utility is far easier to use and have more features, but knowing how to do this on any *nix based host right out of the box might be of interest to you or others. I hope you find what you're looking for. Thanks for asking!
 
Last edited:
  • Like
Reactions: grahamperrin

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
DEVONtechnologies EasyFind might be of interest. http://www.devontechnologies.com/products/freeware/


sudo grep -R -C 2 -i soughtpattern /temp

I'm no expert. You'll find good answers in Stack Exchange, http://stackoverflow.com/a/9083/38108 and so on.

Perfect! :)

Thank you!!!!

I like being able to rely on Unix. I still wish there were a program like FLP on the mac. Maybe someday (EasyFind is as close as I've seen, but still not there functionally compared with FileLocator Pro. FLP is the ONLY program I still miss from Windows.)

Thanks again!

- m

P.S. (EasyFind doesn't do RegEx searches across binary files like the one I needed that I saw, but I do use it for most searches where the programs that (lazilyl) rely on the Spotlight index fail miserably.)
 
  • Like
Reactions: grahamperrin

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
I tried to enhance the RegEx to only look for things like:

level >=3
level = 3
level <=3
level < 3
level > 3

Using this RegEx: grep -Ril -i 'level\s*([>|<|=]|<=|>=)\s*3' ./temp

Now, using the Mac utility "RegExRx", this Regex works fine.

Using FileLocator Pro on Windows, it also identififes all the files with this string.

Yet, when running this on the Mac in Terminal, the prompt just returns. Nothing was found.

If I revert to the RegEx from yesterday, it works again.

So, why doesn't the Mac like this new RegEx?

Thanks,

- m

upload_2016-7-3_7-24-21.png
 

aarond12

macrumors 65816
May 20, 2002
1,148
108
Dallas, TX USA
Yet, when running this on the Mac in Terminal, the prompt just returns. Nothing was found.

If I revert to the RegEx from yesterday, it works again. So, why doesn't the Mac like this new RegEx?

My wild guess is that one of your operators (<, >) needs to be escaped out (\<, \>)... I find it amusing that you're big into RegEx but you're new to the UNIX command prompt. I always felt those two went hand-in-hand. ;)
 
  • Like
Reactions: grahamperrin

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
My wild guess is that one of your operators (<, >) needs to be escaped out (\<, \>)... I find it amusing that you're big into RegEx but you're new to the UNIX command prompt. I always felt those two went hand-in-hand. ;)

Perhaps you're not a software developer? :)

In Java, and other langs, RegExes are used all the time. My favorite Mac Unix book is: "Mac OS X Unix". I refer to it as needed, but Unix isn't what I spend most of my time doing so my Unix skills are always a work in progress...

BTW, I already had looked for possible need to escape some of the characters, but didn't find any of these characters listed. And, since RegExRx works fine (did you see the screenshot above?) as does FLP, I was posting.

Thanks for your reply.

- m
 

jasnw

macrumors 65816
Nov 15, 2013
1,039
1,135
Seattle Area (NOT! Microsoft)
Didn't know about RegExRX, so thanks for that. RE your problem in Terminal, one big issue with regex usage is that it's inconsistent across applications, something you probably know. In looking at RegExRx descriptions I see mention of a capability to translate from the expression you have working within RegExRx to an expression which will accomplish the same result when run within a particular application. Since I don't (yet) have RegExRx I don't know how, or if, this works, but if does do this you should be able to get an expression that matches the grep implementation in whatever Unix shell you're using in Terminal (probably bash, unless you've changed it to something else like tcsh (which I use)).
 

Mork

macrumors 6502a
Original poster
Jan 9, 2009
539
34
Cool, good information. Thanks! :)

In a pinch, I could always modify the RegEx to: grep -Ril -i 'level\s*.*\s*3' ./temp
(which works.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.