Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to do a simple regex search recursively through a directory that isn't restricted to single lines.

I tried grep and ack, but neither seem to support this.

I know it shouldn't be too computationally expensive (in my case) because my text editor of choice (Sublime Text) can do it just fine.

I'm just looking for a simple command-line version of this. Google has turned up pcregrep, but I can't seem to find that for Mac. Am I just not looking in the right place?

share|improve this question
1  
Giving an example of what you're looking for would be helpful. And does grep with context help you find what you want (-C1)? – mjb Jul 7 '11 at 13:59

Install Homebrew and then:

brew install pcre

This will give you the latest pcregrep

share|improve this answer

You didn't say exactly what you're looking for so I'll imagine the task to find out whether the file contains 112 followed by 223, disregarding newlines.

A slightly contrived awk solution:

awk -vRS='' '/112.*223/ { print "found it"; exit }' file.in

The RS variable contains the record separator. By setting it to the empty string, the whole file will be read as one record.

This will probably be very memory inefficient on large files.

By the way, I'm doing this on OpenBSD, but the OS X awk ought to work the same way.

share|improve this answer
    
I'm on OS X 10.11.2 and get "awk: invalid -v option" – HaggleLad Mar 17 at 10:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .