Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replace

Doug P edited this page Jan 12, 2025 · 1 revision

Performing replace

To perform replace a search has to be performed first.
Once the search is complete and the new text is entered in the "Replace with" field, the "Replace" button will become enabled.
For regular expression replacement refer to Regular Expressions section.
For XPath replacement refer to XPath section.
dnGrep does not replace in binary file formats such as Word, Excel, PowerPoint, PDF, ebooks, files in archives, images, audio files, or executable files.

There are three options for doing replace:

  • The full Replace dialog which can preview the change for each match found in the search and allows accept or reject of each change.
  • A Replace dialog showing only the files and allows accept or reject of all changes in each file. This will be faster as it does not load each file for preview.
  • Replace from the main window, which will replace all matches in the selected files in the results tree.

The Replace button will remember your previous choice, but to change the selected option, click the drop-down arrow on the Replace button. To choose between the first options using the Replace dialog, open the Options dialog and in the Layout section, Replace window layout, choose between 'files and individual matches' and "files only".

Previewing changes

The Replace dialog has two ways to preview changes. If you are using the full dialog showing the file preview, enable or disable previewing changes using the checkbox just below the preview pane. In both full Replace dialog and the files only dialog, you can also click the "Open file compare" button to open the preview in an external comparison application, if you have one configured in the Options dialog.

Special characters

Special characters can be inserted while doing the replace:
\\t - tab
\\r - return
\\n - newline
\\0 - null
\\a - bell
\\b - backspace
\\f - form feed
\\v - vertical tab

GUIDs

dnGrep can insert GUIDs while doing the replace:
$(guid) - inserts a different lowercase GUID in the place of each match
$(GUID) - inserts a different uppercase GUID in the place of each match
$(guidx) - uses the match string value as a key to insert a unique GUID for each different original value, or the same new GUID where the original was repeated

For example, if you need to change the GUIDs in a file with several GUIDs, some repeated and some unique, use a regular expression like
[a-fA-F0-9]{8}[-]?([a-fA-F0-9]{4}[-]?){3}[a-fA-F0-9]{12}
and use $(guidx) as the replacement pattern. All the GUIDs will be replaced, and each repeated original GUID will get the same new value.  

 

Clicking the "Replace" button will bring up the replace window.
In this window you will be able to choose which matches to replace, or replace all.

  • Replace in files - to replace all matches in all files, and run the replace
  • Replace in file - to mark all matches in the current file for replacement
  • Replace - to mark the underlined match in the current file for replacement

Use the "Next"/"Previous" buttons to move through matches in the current file, or move to another file.

Use the "Undo" buttons to modify your selections before the replace starts.

Click the "OK" button to close the window and begin replacing the marked matches.

After the replace the results of the replace can be rolled back using "Undo" button.

Clone this wiki locally