0

I am looking for a gratis, Windows-based, text search and replace application which will allow me to make the following kinds of replacement, allowing me to specify file extensions and giving the option to process a directory tree.

Let’s say I have lots of PHP code which says, on two consecutive lines:

echo(“Some message”);
Die();

and I would like to replace all such occurrences with a single line call to a new function:

EchoMessageAndDie(“Some message”);

Is that clear enough? Please feel free to ask me to explain. It seems like some sort of templating would be necessary to define the various parts of the search/replace strings.

Multiple lines would be a bonus, rather than just two, if possible. Standard search/replace options such as case sensitivity, whole words, etc would also be welcome. In fact, the more features the better, so long as it is gratis, for Windows and can make replacements such as the example given.

[Update] my bad. I forgot to state that I need this to operate on all files in a given directory tree.

2 Answers 2

3

I've actually had good luck with grepWIN for this purpose. It processes folders recursively, does multiline search and replace, can filter by file extension, do plain text or regex, and has a fairly verbose output that displays files found as well as locations in the files where the matches are.

It's one of my "first installs" for a clean machine. (Note: I'm not affiliated with this project. I just like using it and think it works for you're looking for.) GitHub

Screenshot

1

Try any professional text editor, like Atom, Sublime. Most IDEs should be able to do this, too, like PhpStorm (not free) or Aptana Studio (I assume. I didn't test it with Aptana).

For example, in Atom you can use regular expressions, search and replace multiline, through any document tree you like and just search in files with specific extension or name pattern and so on. This feature is very powerful (as it is in any other professional text editor).

Find and replace in Atom

3
  • You are correct, and I have upvoted you. I hadn't thought about regex, because I like to avoid it where I can. I suppose that that is the solution, but then I would have two problems ;-) My problem is that my command of regex is not very great. Probably not good enough to do this; and certainly not good enough get the correct indentation on the remaining line; but, that is probably a question for S.O)
    – Mawg
    Commented Apr 24, 2019 at 9:58
  • 2
    Thanks! If you are unsure about regexp, you might want to try them before replacing everything - you can use regex101.com to do that. And sure, feel free to ask at SO :)
    – Micha
    Commented Apr 24, 2019 at 10:04
  • my bad. I forgot to state that I need this to operate on all files in a given directory tree. Sorry
    – Mawg
    Commented Mar 24, 2021 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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