2

Is there a way to search files for matches to a regular expression?

I would like to search all files of a specific extension for matches to this expression: ^ := '([a-z0-9]{3})'$

I would also like it to return (or even better jump to) the line(s) that match.

0

5 Answers 5

3

Agent Ransack will do it.

1
  • Free version does not have multi-line regex search. Just saying. Commented Nov 24, 2017 at 10:20
1

Also look in to AstroGrep, great little program for going just this.

1

I think you'd want to do something like this:

find / -name *EXTENSION -exec grep "^ := '([a-z0-9]{3})'$" {} \;

It searches the whole drive (/) for any files ending in EXTENSION and then runs grep with your pattern on that file. You can insert any grep flags in there to get more specific behavior, but by default it prints out the file name with its matching line.

As Dan suggests, you can further combine this with sed to actually manipulate the matching files.

1
  • This will work out of the box if vaccano is running linux. If not, these commands can be run using cygwin.
    – Jarvin
    Commented Jul 9, 2010 at 18:02
0

Fastest search tool you will ever see is Everything It does not make index, instead it directly access the NTFS records and find your file without even looking and iterating through your hard drive

It supports regular expression

It is my everytime search tool, it shows the result while you are typing, what can be more faster than that?

6
  • Interesting, but I don't know that my hard disk is big enough to "Download Everything for Windows 2000, XP, 2003, Vista, 2008 and Windows 7" ;-)
    – user31438
    Commented Jul 9, 2010 at 21:42
  • Looking at the FAQ though - item 1.3 "No, "Everything" does not search file contents, only file and folder names.", which I think means this doesn't answer the question - though the wording of the question isn't clear.
    – user31438
    Commented Jul 9, 2010 at 21:45
  • Its name often confuses while i tell others about it :P , Yup, i am a poor reader and didn't read the last 2 lines of the question with mind. Anyway it will help a lot in your daily file search tasks
    – LifeH2O
    Commented Jul 11, 2010 at 19:37
  • Everything DOES make an index just not a very big one.
    – snowdude
    Commented Jan 25, 2012 at 11:09
  • Yes it does make an index, but takes a very little time to do that.
    – LifeH2O
    Commented Jan 1, 2013 at 12:30
-1

sed("stream editor") will do it. They have Sed for windows as well as for linux (it should be in your package manager if it isn't already in the default install.

3
  • sed seems an inappropriate answer - it doesn't just find, it modifies. The classic Unix program for regex search is grep, and there are certainly Windows versions around. There will certainly be a version in MSYS - but that's kind of a heavyweight solution if all you want is grep.
    – user31438
    Commented Jul 9, 2010 at 21:40
  • @Steve314: Perhaps it is an overly complex solution... but it works perfectly fine. Sed can for the most part encompasses all of greps functionality and a whole lot more, for example a basic grep done in sed is: 's/pattern/&/p'`. Nerdling's answer of course is much better because it includes the find statement and everything.
    – Jarvin
    Commented Jul 9, 2010 at 23:07
  • I should have read up on sed again before commenting anyway. Based on vague memories, I thought it edited files in-place. Since it actually edits streams (I should have known really - it's in the name) its a much more sensible answer than I thought.
    – user31438
    Commented Jul 12, 2010 at 19:48

You must log in to answer this question.

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