Vaishnavi502 / find-replace

Powershell script that finds specific words in a text file and replaces them in a word document

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Find-Replace for specific words

Powershell script that finds specific words in a text file and replaces them in an MS word document

Target group

  • Editors and writers
    • Purpose: To replace commonly used phrases and words without needing to find and replace using MS Word's built-in function every time
    • Automated replacement of words in British English to American English or vice-versa is useful through this
    • Replacement of non-hyphenated words, use of en-dash or em-dash for certain commonly-used phrases is possible through this

About find.txt:

  • A new phrase should be of the form: {old word(s)}:{new word(s)}
    • Note: There shouldn't be any space after the colon unless you want an extra space upon replacement
  • All occurrences of the words will be replaced in the word doc

Prerequisites:

  • Powershell script must be allowed to run as per execution policy
    • Check that your policy is either RemoteSigned, AllSigned or Bypass In case it is not, open Windows powershell using Run as Administrator and using
      Get-ExecutionPolicy
      Set-ExecutionPolicy -ExecutionPolicy <your preferred policy>
  • The doc file you want to modify must be closed before running findrep.exe

Steps to follow before running findrep.exe:

  1. Open findrep.ps1
  2. Find the line
    $words=Get-Content C:\Users\DELL\Desktop\find.txt
    image and replace the path with path to your find.txt
    $words=Get-Content <your path>\find.txt
  3. Now open Windows powershell and install the module ps2exe which will convert the findrep.ps1 to an .exe file image
  4. After installing ps2exe, you can now invoke it to convert findrep.ps1 to .exe: image
  5. Now double-click findrep.exe and you will be asked the file name in the cmd of the MS Word doc that you want to modify: image Provide the path to the word document you want to modify
  6. Everytime changes are made to findrep.ps1 you will need to re-create the .exe file using ps2exe

About

Powershell script that finds specific words in a text file and replaces them in a word document


Languages

Language:PowerShell 100.0%