Replace A name for 300 others in the list and save.
-
Hello everyone,
Need a help once again.
I have an invitation to make, but since there are many (300), I need to replace the name of each guest. Below is the beginning of the invitation.
"Dear Richard, how are you?
I would like to invite you to access our scientific technology hub.
It will be available in room 19 until next Monday."
I need to replace the name “Richard” with 300 other names that I have in a text list and save a file for each name changed.
Does NP++ do this?
Thank u in advance
Claudio Raphael
-
Not natively. But search the forum for mailmerge or mail merge to find solutions
-
Check this out – it might help with a large number of replacements.
-
@Claudio-Raphael another method that might be easier to implement is to use a batch script (which are best created in NP++) to make each text file from a template.
Assuming that you have the invitation template saved to
template.txt
, and the list of names (written out line-by-line) saved tonames.txt
, the code below should do what you want. Note that the text files and.bat
file should all be in the same directory.cd %~p0 for /f "tokens=*" %%n in (names.txt) do ( type template.txt > %%n.txt powershell -Command "(Get-Content '%%n.txt').replace('Richard', '%%n') | Set-Content '%%n.txt'" )
EDIT: added a
cd
line so that the script can be run from NP++'s Run feature.EDIT 2: if you install the RunMe plugin, the first option in its menu (which seems to have a default shortcut of
Shift
+F5
) will allow you to run the script from NP++ more directly (i.e. bypass the dialog). This also allows the original version of the code above (i.e. the one without thecd
line) to run as expected. -
P PeterJones forked this topic
-
All,
The “what advice is on topic” tangent has been moved here to not clutter the actual queestion here.
Assuming you come back, if you have questions or need help with the Multi-Replace plugin solution, or the Mail Merge using the PythonScript plugin solution, feel free. If you have questions about how to interface @mathlete2’s suggestion with Notepad++, you can ask here… but detailed questions about the cmd.exe/batch syntax and the powershell command are better asked in some other group of super users of their computers or forums dedicated to Windows shell commands.
if you install the RunMe plugin
Unnecessary and an extra complicated step for this task. If you really want to run the saved contents of the active file (like if the file is saved as
replacement.bat
), then Run > Run… =cmd /c "$(FULL_CURRENT_PATH)"
is sufficient, without installing a plugin first. That Run menu command can be created, saved, and run through the menu or (optionally) even with a keyboard shortcut, all without the need for the plugin. The specific Notepad++ Run command will launch the active file using it’s default verb – “open” or “run” or whatever Windows Explorer shows when you right click it – ie, the same that Explorer would run when you double-click the file, and , the same as if you typed the name of the file at thecmd.exe
prompt or the Windows Run command (WIN+R
) -
@PeterJones said in Replace A name for 300 others in the list and save.:
[in reference to installing the RunMe plugin] Unnecessary and an extra complicated step for this task.
No more complicated than the installation of the plugins required for the other suggestions…
If you really want to run the saved contents of the active file (like if the file is saved as replacement.bat), then Run > Run… = cmd /c “$(FULL_CURRENT_PATH)” is sufficient
Except that this triggers a dialog - one that not only requires an extra click to proceed, but whose content is lost when you close NP++. This obviously isn’t ideal if you plan to use this technique again in the future. By installing the RunMe plugin, you can simply use a slightly different menu item/shortcut to do this all in one step.
-
@mathlete2 said in Replace A name for 300 others in the list and save.:
No more complicated than the installation of the plugins required for the other suggestions…
My point exactly.
Except that this triggers a dialog - one that not only requires an extra click to proceed, but whose content is lost when you close NP++. This obviously isn’t ideal if you plan to use this technique again in the future.
Have you ever seen the Save button in the Run dialog?
This allows you to save the command, which will put it into the Run menu as a separate entry from then on – it is not lost after you close N++. You can even assign a keyboard shortcut when you save it. I literally have that command in my run menu right now, and it’s been there for years. After that first setup in the Run… dialog from the Run menu, it’s part of Notepad++ as long as you don’t delete it from
shortcuts.xml
, and it will never need the dialog again. This is perfect if you want to use this technique again in the future -
@PeterJones said in Replace A name for 300 others in the list and save.:
No more complicated than the installation of the plugins required for the other suggestions…
My point exactly
Don’t forget: those other suggestions required additional setup steps on top of the plugin installation.
@PeterJones said in Replace A name for 300 others in the list and save.:
Have you ever seen the Save button in the Run dialog? This allows you to save the command, which will put it into the Run menu as a separate entry from then on
Nice! That’s definitely great for standard usage, but I noticed that the RunMe plugin has extra options for running with Administrator privileges. AFAIK, Windows doesn’t have a
sudo
equivalent, so this plugin still has its uses. -
@mathlete2 said in Replace A name for 300 others in the list and save.:
My point exactly
Don’t forget: those other suggestions required additional setup steps on top of the plugin installation.You had previously said (in one of the posts moved to another discussion), “if you didn’t already have those tools in place”. But part of your solution was to also install a tool that wasn’t already in place. So you were calling me (and others) out for doing what you were also doing: recommending extra steps.
@PeterJones said in Replace A name for 300 others in the list and save.:
Have you ever seen the Save button in the Run dialog? This allows you to save the command, which will put it into the Run menu as a separate entry from then on
Nice! That’s definitely great for standard usage, but I noticed that the RunMe plugin has extra options for running with Administrator privileges. AFAIK, Windows doesn’t have a
sudo
equivalent, so this plugin still has its uses.I didn’t say it could do everything that the RunMe plugin has done – I’ve never used that plugin – I was just pointing out that Notepad++ could natively do what you suggested be done with the RunMe plugin, so that the extra plugin wasn’t necessary.