I am using Powershell V2.0
I have a string in file:
"-PatchInfo-" = "-HFInfo-"
I want "-HFInfo"
to replace with a string 1234 "-PatchInfo-" = "-HFInfo-"
. File should look like after replacement:
"-PatchInfo-" = "1234" "-PatchInfo-" = "-HFInfo-"
I am using command
(gc filename.txt) -replace "-HFInfo-",'1234 `n \\"-PatchInfo-\\" = \\"-HFInfo-\\"' | Out-File filename.txt
But I am unable to get line break after executing this command. I tried various other possibilities as well but couldn't make it.
Can anybody suggest what I am missing here?
(gc filename.txt) |% {$_.replace("-HFInfo-","`"-PatchInfo-`" = `"1234`"`r`n`"-PatchInfo-`" = `"-HFInfo-`"")} | Out-File filename.txt
Will produce:
"-PatchInfo-" = "1234"
"-PatchInfo-" = "-HFInfo-"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.