PowerShell script for mass word replacement in text


PowerShell script for mass editing: Text editors like Notepad and Notepad ++ are used to create many different file types such as log files, 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 the free word processing application Notepad + +. You can download and use the application. 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 need to replace the 'initial-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

Registration in iGuRu.gr via Email

Enter your email to subscribe to the email notification service for new posts.

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

_____________________________________________


Read them Technology News from all over the world, with the validity of iGuRu.gr

Follow us on Google News iGuRu.gr at Google news