How to replace multiple strings in a file using powershell -


I am writing a script to customize a configuration file. I want to change many examples of strings inside this file, and tried to use power shield to get me a job. It works well for one place, but doing so is very slow because every time it is complete The file has to be re-parsed, and this file is too large, the script looks like this:

$ original_file = 'path \ filename.abc' $ destination_file = 'path \ filename.abc .new '(found-content $ parent_file). Fortech-object {$ _-places 'some 1', 'some 1 NU'}. Set-content $ destination_file

What I need is something like this, but I do not know how to write it:

  $ original_file = 'path \ filename .abc '$ destination_file =' path \ filename.abc.new '(found-content $ parent_file). Fork-object {$ _- replays' some 1 ',' some 1a '$ _-place' some 2 ',' some 2bb '$ _-place' some 3 ',' some 3cc '$ _-' Change some 4 ',' some 4 '' some 5 ',' some 5dsf '$ _ - some' 6 ',' some 6 dfff ''}. Set-content $ destination_file  

An option restore chain Operation Together At the end of each line, the ` avoids the new line, due to which PowerShell continues to parse the expression on the next line:

  $ original_file = 'path \ filename.abc' $ destination_file = 'path \ filename.abc.new' (found-content $ parent_file). Fork-object {$ _- some '1', 'some 1a', 'something', 'some 2', 'some 2bb' '-3', 'some 3 cc', 'some' 4 '' , 'Some 4' '' some '', 'some 5dsf' `6 '' some 6 ',' some 6 dff ''. '| Set-content $ destination_file  

Another option would be to assign an intermediate variable:

  $ x = $ _ 'Some 1', 'some 1a' '$ x = $ x -replace' some 2 ',' some 2bb '... $ x  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -