how to replace data in notepad++ tab with respect to other tab data?
-
Good Day,
how to replace data in notepad++ tab with respect to other tab data?
for example, i have XML tab, now i want to apply find & replace function into that xml tab using notepad++ with respect two other tabs 1) FIND and 2) Replace
- FIND tab will contain the text which is present/appear in XML tab.
- REPLACE tab contain the text which is required to replace in XML tab
BR,
Genjua
-
Notepad++'s find-and-replace doesn’t work that way. If you want to edit
FILE1.xml
, there is no way with Notepad++ alone to populate the FIND value fromFILE2.find
and REPLACE fromFILE3.repl
.Notepad++'s find-and-replace works on one file at a time, with the FIND and REPLACE fields being manually entered.
if you want to automate the process, you’d have to use something like one of the Notepad++ scripting plugins, like PythonScript. There are examples of scripts for PythonScript that do things like “mailmerge” and “translate” (you can use the forum’s search feature to find them), both of which come close to what you want – though I think the “translate” will be closer: right now, my “translate script” published here takes a hardcoded list of OLD-vs-NEW pairs… but it could be changed to read the Nth line from
FILE2.find
as the OLD and the Nth line fromFILE3.repl
to use for the search-replace rather than the hardcoded table. -
Hello, @genjua-khan, @peterjones and All,
@genjua-khan, in addition to the @peterjones’s solutions, may be the following
Python
script could interest you !The explanations, regarding the use of this script, are included in comments
Note that the
RULIC
name of that script means Replace Using List In Clipboard !
''' Based on : https://notepad-plus-plus.org/community/post/33977 ( Scott Sumner - August 2018 ) - Given a NEW tab, containing some lines, with the FORMAT : DELIMITER<Searched_Text>DELIMITER<Replacement_Text>, PASTED in the CLIPBOARD by a 'CTRL--C' action - This script REPLACES any 'Searched_Text' ( of a 'CLIPBOARD line' ) with its CORRESPONDING 'Replacement_Text', in CURRENT file ( ACTIVE tab ) EXAMPLE : Let's suppose that the THREE lines, below, are pasted in the CLIPBOARD : !bar!foo $Test$ :Bob:Ted Then : - Any 'bar' string will be changed by 'foo' in the present ACTIVE tab - Any 'Test' string will be DELETED in the present ACTIVE tab - Any 'Bob' first name will be changed by 'Ted' in the present ACTIVE tab NOTES : - IF the 'Replacement_Text', after the DELIMITER, is ABSENT, the 'Searched_Text' is then DELETED - The DIFFERENT strings, to search for, are ALWAYS supposed to be LITERAL strings - The DELIMITER may be DIFFERENT between TWO successive lines - The list of the different SEARCHES [ and REPLACEMENTS ], with the DELIMITERS, must be PRESENT in the CLIPBOARD, RIGHT BEFORE running this script ''' import re def RULIC__main(): if not editor.canPaste(): return cp = editor.getCurrentPos() editor.setSelection(cp, cp) # cancel any ACTIVE selection(s) doc_orig_len = editor.getTextLength() editor.paste() # Paste so we can get easy access to the clipboard text cp = editor.getCurrentPos() # The POSITION has moved because of the PASTE action clipboard_lines_list = editor.getTextRange(cp - editor.getTextLength() + doc_orig_len, cp).splitlines() editor.undo() # Revert the PASTE action, but sadly, this puts it in the undo buffer...so it can be redone editor.beginUndoAction() for line in clipboard_lines_list: try: (search_text, replace_text) = line.rstrip('\n\r')[1:].split(line[0]) except (ValueError, IndexError): continue editor.replace(search_text, replace_text) # DEFAULT search is SENSITIVE to case #editor.replace(search_text, replace_text, re.I) # If an INSENSITIVE search is preferred editor.endUndoAction() RULIC__main()
Best Regards,
guy038