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 on
-
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.
-
@PeterJones said in Replace A name for 300 others in the list and save.:
You had previously said: “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.
By “tools”, I wasn’t just referring to the plugins - there appears to be extra setup work required to make those plugins usable for this sort of thing, and it’s not immediately obvious what precisely needs to be done to accomplish this particular task. The plugin that I mentioned doesn’t require any extra setup work to use as described.
Also, when I mentioned that plugin, I did so as part of an edit - one that was intended to be interpreted as an optional alternative. It’s up to users to decide whether or not it’s worth their while to use that alternative…
-
In the fork, @mathlete2 informed me:
While there may well be a ready-made solution somewhere within those search results, the post that contains the solution is not identifiable at a glance…
Sorry, I had intended my link to make things reasonably easy, though requiring a little effort of reading some pre-existing posts. If this had been Stack Exchange, I would have been expected to just “close as duplicate”, since the question is already answered somewhere else, but I think that’s harsh; but maybe my expecting someone to search the forum is also too harsh. (I guess even SE’s close-as-duplicate link to the original; it’s apparently time for me to stop just giving people the keywords to search for and instead just finding the exact post myself.)
is not identifiable at a glance.
I thought that the post that the preview shows as “Let’s call the script
MailMerge.py
” would be easily noticed by looking through those results… but I guess not.So here is the post I was intending for @Claudio-Raphael or anyone else to find – it presents a fully-working PythonScript solution; for those who don’t know how to make use of a solution using the PythonScript plugin, this FAQ explains the steps needed.
Sometimes these scripts for the PythonScript plugin get multiple versions, depending on customizations that people request; I don’t remember whether MailMerge has been customized one or more times in other of the search results; so if the one I linked to is not exactly the solution desired, checking out some of the other posts in that search might find alternate versions of the script which will work better in your circumstances.
TL;DR
The
MailMerge.py
script is here – sorry for any confusion.