0

Many answers show how to replace the text, but I want to keep the original file, I want the replaced file to be in another path and with the new name, such as, rename test.txt to test_replace.txt.

1 Answers1

0
$original_file = "C:\Users\boxman\Documents\test.txt"
$path_copy = "C:\Users\boxman\Documents\test1.txt"

$content = Get-Content -Path $original_file

$content = $content.Replace("1","_9_")

$content | Out-File -FilePath $path_copy

This reads file content, replaces what needs to be replaced then creates another item in another path...

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 19 '22 at 03:21