Mac Program For Grep

  1. How To Grep On Windows
  2. Mac Program For Grepolis

Windows Grep, Find & Replace with data extraction AJC Grep is a powerful file finder, text search, replace and data extraction program for Windows. This is a major time saving tool for developers, documenters, web designers and anyone who has to search. Grep is an application for loading and searching through large text files. Interpret text documents in any encoding supported by Mac OS X; Highly optimized loading and matching of very large text files.

Active6 months ago

I would like to update grep on my Mac to a more recent version than 2.5.1, which came with Mac OS 10.7.2. My question is: what is the best way to update grep (or any similar program) for the Mac? I could use Fink or MacPorts to install a new version and set my path variable to look in the appropriate branch of the file tree, or I could update the grep program in usr/bin, or perhaps there's another approach that I haven't considered. Because I am relatively new to the command line and the Unix back-end of the Mac, I'm concerned about breaking something. That said, I'd certainly be willing to compile the most recent stable release of grep from source and install it in /usr/bin if that's the appropriate method. In case anyone wonders why I'd want to update grep from 2.5.1, I have two reasons: 1st, I'm learning to use grep with a reference book that is based on 2.5.3 (probably similar, I know); 2nd and more importantly, I want to learn how to update such programs simply as a matter of administrating my own system effectively.

Walery Strauch
4,1386 gold badges38 silver badges51 bronze badges
GregoryGregory
1,3556 gold badges21 silver badges37 bronze badges

3 Answers

As you said, you may use Fink, MacPorts, etc...

But if you just want to update grep, you may want to grab the sources, and compile them.

If you decide to go with this option, don't install it in /usr/bin.

If you do so, you will overwrite something needed by your OS.
So with another version, you may encounter problems, as the OS will except another version.

And also, if you do so, you'll have problems when updating your OS, as it might overwrite your own version.

So if you want to compile it, place it in /usr/local/bin (usually with the --prefix option), and update your path environment variable.
This is the safe way.

Usually, compiling such a program is just the standard ./configure, make and sudo make install stuff.
But be sure to take a look at the compiling options first, by typing:

Mac Program For GrepMacmadeMacmade
43.6k11 gold badges96 silver badges117 bronze badges

The following is a very elegant solution from http://www.heystephenwood.com/2013/09/install-gnu-grep-on-mac-osx.html

PhysicalChemistPhysicalChemist

It's gotten easier recently:

Which causes lines like the following:

Then you would use:

Mac os x grep manMac Program For Grep

Anywhere where you would have executed grep before.

phyattphyatt
14.9k2 gold badges35 silver badges55 bronze badges

Not the answer you're looking for? Browse other questions tagged macosgrepadministration or ask your own question.

Active9 years, 9 months ago

This is a question coming from a former/current Windows user. If I'm looking at a Finder window in a particular directory, how can I search for files with names matching a particular pattern (e.g. 'p*.php') that contain a particular string of text?

Chealion
22.6k7 gold badges61 silver badges71 bronze badges
Jason SJason S
3,04311 gold badges53 silver badges74 bronze badges

5 Answers

You can't do this from the spotlight icon in the menu bar. But you can do it with spotlight:

  1. Navigate to the folder in the finder.

  2. Type your search of the content in the file you are searching for in the search bar on the top right of the folder.

  3. There is a line above the results that says: Search: This Mac 'Your Folder Name' Click on the name of your folder to restrict the search to the folder instead of the whole computer, which is what the default selection 'This Mac' does.

  4. Then click the gear icon, choose show search criteria, and narrow down your search. For example you can add 'Name ends with .php' and then click the plus to add another criteria. You could then add 'Name begins with p'

Edit: I just grabbed a php file and searched for this string array_push($songs,$song) and it will not find the file, but if I only search up to the comma (ie array_push($songs ) spotlight does find the file!

I found this article which explains how to add php as a supported file type for spotlight which should fix the weird result I experienced above. I believe without this change spotlight treats the file as rtf only so some php elements (punctuation especially) will make the search fail. The command to edit the required file is:

You'll want to reindex after this change as the article mentions. It also mentions the more proper way to do this is to install the developer tools.

You can then use the method I described above to restrict your search to a specific folder or file type.

ridogiridogi
2,6571 gold badge13 silver badges24 bronze badges

One simple way is Spotlight, in the upper right hand corner of the file window or the desktop screen; that's plain text for file names and strings. Grep is possible with Terminal and *unix commands (Terminal is in Applications/Utilities/). There's Aqua Command-Line Tools, though it looks old.

markratledgemarkratledge

Some programmer's text editors offer a grep-like feature for searching for a regular expression across multiple files; many (many) moons ago BBEdit had this feature (and probably still does; I just haven't used it for years). I wouldn't be surprised to find that other tools targeted at the developer market also have similar features.

larskslarsks

Both Spotlight and the Finder are an attempt at reaching out to the sort of people who keep the 'For Dummies' line of books on shelves, and as such, are not capable of parsing regular expressions or anything else particularly fancy. A lot of people like PathFinder as a replacement but I find it more trouble than it's worth since the Finder will keep launching itself no matter what you do.

Hasaan ChopHasaan Chop
4,1761 gold badge14 silver badges13 bronze badges

How To Grep On Windows

Using AppleScript (and do shell script to use Perl) it's possible to run a script to select all the files that match a regular expression. This can be combined with programs such as FastScripts and is actually documented and available for download by the developer on his blog.

ChealionChealion
22.6k7 gold badges61 silver badges71 bronze badges

Mac Program For Grepolis

Not the answer you're looking for? Browse other questions tagged macosfinderfind-in-files or ask your own question.