Find/Replace text string in multiple files using criteria from a Look-up Table?
I have thousands of .txt files, and among hundreds of lines of text each file also contains an alphanumeric string that is a Unique Identifying Number preceded by a code denoting the line as containing the UID (e.g., UID. 12-345-67891).
Is it possible to run a batch Find/Replace across all of the files to change the format of the UID (to 12345678910000) using a look-up table?
I have only used NPP for basic functions such as Find/Replace in Files, but I do have some familiarity with Python Script.
PeterJones last edited by PeterJones
But if really what you want is “two digits, hyphen, three digits, hyphen, five digits” converted to “those two, those three, those five, four zeroes” (it’s impossible to know, because you didn’t define your search/replace needs very well: a single instance is almost never enough to determine what you really want, though it can make for some entertaining guesses on our part).
(edit make sure to use Find in Files dialog/tab, not just the Replace)
- data =
12-345-67891 98-765-43219 55-555-55555
- find =
- replace =
- search mode = regular expression
- result =
12345678910000 98765432190000 55555555550000
If this isn’t what you want, you’ll have to give a better example.
FYI: if you have further search-and-replace (regex) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting the data so that the forum doesn’t mangle it (so that it shows “exactly”, as I said earlier), see this help-with-markdown post, where @Scott-Sumner gives a great summary of how to use Markdown for this forum’s needs.
Please note that for all “regex” queries – or queries where you want help “matching” or “marking” or “bookmarking” a certain pattern, which amounts to the same thing – it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.
@PeterJones Thanks for the quick response. The reason I only gave one example is because all of the UIDs are in the same format (##-###-####), but I want to convert them into a new format (##########0000).
The reason I am asking about using a look-up table is because I have THOUSANDS of files to go through, and each one contains a totally different UID, hence the Unique in Unique ID. If the exact same UID was present in each file, then I would just use Find(/Replace) In Files to search them all for that one specific UID and replace it in bulk. Since there are thousands of entries to make, using Find(/Replace) In Files I would have to enter a new value manually for each file, and repeat thousands of times. Its easy for me to generate a look-up table containing the UIDs in their existing format in one column and the desired format in another column. The difficulty is finding the software that can read that table and make the thousands of individual changes in bulk. I’m hoping NPP can do it. If not, I may have to go with a PowerShell script.
Does that clarify?
PeterJones last edited by PeterJones
Based on your description, my regular expression solution should work for you. Does it?
edit: you should probably try on a single file first (backing up the file before trying) before trying with the FindInFiles
Alan Kilborn last edited by
but I do have some familiarity with Python Script.
Due to that, Maybe the script here is of some interest as a starting point if the other approach gets too burdensome: https://notepad-plus-plus.org/community/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others
@PeterJones This worked perfectly, with no need for a look-up table. Thank you so much.