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.
            Asked
            
        
        
            Active
            
        
            Viewed 34 times
        
    0
            
            
         
    
    
        user19418817
        
- 33
- 5
- 
                    What have you tried so far? – boxdog Jul 15 '22 at 15:46
- 
                    [link](https://stackoverflow.com/a/30893960/19418817)This is the answer I'm reading, I don't know how to improve it to suit my needs – user19418817 Jul 15 '22 at 15:51
- 
                    `[System.IO.File]::WriteAllText("YourNewPath", $content)` maybe? – Charlieface Jul 15 '22 at 17:06
1 Answers
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...
 
    
    
        Evaldas Blauzdziunas
        
- 28
- 4
- 
                    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