In addition to searching, Windows Grep can also perform string replacements. This feature can be extremely useful for globally changing variable names in a large number of source code files, for example, or modifying HTML tags on web pages.
Note that you can only perform replacements in plain ASCII text files.
The replace assistant will guide you through the process of entering the information needed to perform a replace. It will ask the following questions:
The Replace Assistant will show you the string that has just been located, then allow you to enter the string you want to replace it with. This can be the same or different in length to the original string and can even be left blank to have the searched-for string removed from the files. Note that regular expressions are not recognised in replace strings - they will be inserted into the file verbatim.
If you had a file selected in the file list window when you invoked the Replace Assistant, you will have the choice of either replacing in the single file highlighted, or in all files found. Otherwise, the replace will act on all files in the file list.
You can elect to change the original files, or leave the originals intact and save the changes in a different file. If you choose to change original files, a backup will be created called <original filename>.bak. If you choose to make copies, changes will be saved in <original filename>.new. So even if you change the originals but make a mistake you can get back the unmodified files.
You have the choice of having Windows Grep make changes to the file(s) without further intervention, or you can get it to show you every replacement it is about to do so that you can confirm that you want the replacement to go ahead. If you choose the latter, a dialog box will be displayed showing you the line it is about to modify before and after the replacement.
After you have finished replacing, a replace report will be output to the results window, which you can save or print. This will show which files were modified and the number of modifications made to each.