PowerShell script for mass word replacement in text

PowerShell script for bulk text editing: Text editors like Notepad and Notepad++ are used to create many different types of such as logs, scripts, PowerShell files and more. PowerShell

Since the word processor you use can create these files, it can also process them. If you have many text files and you have to replace a few words at all, then you can do it with a PoswerShell script.

The script will do so without having to open each file separately to replace the word. Let's see how you can do it.

You can use almost the same script for other file types that can be created with a word processor.

First, you'll need to place all the text files you want to edit in the same folder. The script will check only one folder and not your entire system.

Many times through this page we have mentioned her word processing Notepad + +. You can download and use it . Create a new file, copy and paste the following text:

Get-ChildItem 'path-folder \ *. Txt' -Recurse | ForEach {(Get-Content $ _ | ForEach {$ _ -replace 'original-word', 'new-word'}) | Set-Content $ _

You will need to edit the above script. Replace the "folder path" with the actual path to the folder that contains the text files you collected to edit.

Then you should replace 'start-word' with the word you want to replace. Finally, change the “new-word” and add the word you want to replace the old one.

For example, I have some text files that have the word 'Post' and I want to replace the word post with the word article. See how I converted the above script:

 Get-ChildItem 'C: \ Users \ Language \ Desktop \ files \ *. Txt' -Recurse | ForEach {(Get-Content $ _ | ForEach {$ _ -replace 'post', 'article'}} | Set-Content $ _

Once you've finished the conversion, save your text with the ps1 file extension. In Notepad ++ before saving, be sure to change the file type. Run your script and your files will change.

If you want to use the same script for files other than .txt files, change the file extension to the first line. For example,

C: \ Users \ igure \ Desktop \ files \ *. txt
it should be done
C: \ Users \ Desktop \ Files \ * .xml

Warning: The script does not recognize the words. If you want to replace the word with a, it replaces 'the' where it finds it. Let's say at the beginning of the word theme.

_____________________________________________

iGuRu.gr The Best Technology Site in Greecefgns

every publication, directly to your inbox

Join the 2.101 registrants.

Written by giorgos

George still wonders what he's doing here ...

4 Comments

Leave a Reply
  1. I do not know if I sent the previous one, so I repeat briefly.
    What if instead of replacing a word with another word, I want to replace a word with a variable (file name e.g.)
    I will be grateful for an answer

  2. You helped me a lot. But if instead of a specific word I want to put a variable? Replace δλδ a specific word with a variable (file name). As you already know, these are .cue files. I found 200 folders with different names, each with 2 files all identical to each other, so I can not transfer flac and cue to the same folder in my collection. I converted the files of each folder with the name of the folder but I did not save. Now I have to put the name of the corresponding flac file in each cue inside the File line. I have to open 200 cue one by one.
    Help (sarastrogr@gmail.com)

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).