Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    
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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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