powershell - New line space is lost with reading & setting the content -
i trying read file, put content & save same file using powershell. below script:
$x=file.txt $old='hi' $new='hello' (get-content $x | foreach-object {$_ -replace "$old","$new"}) | set-content $x
file content:
hi world!!!
after running script, new line space getting lost. file looks below:
content after script execution:
hello world!!!
i don't want new line space lost & format should same. expecting output below:
hello world!!!
try using carriage return + new line `r`n
, maybe this:
$new='hello `r`n'
Comments
Post a Comment