Powershell replace lose line breaks
Posted
by Fadrian Sudaman
on Stack Overflow
See other posts from Stack Overflow
or by Fadrian Sudaman
Published on 2010-04-28T03:17:45Z
Indexed on
2010/04/28
3:23 UTC
Read the original article
Hit count: 736
powershell
|regex
Hi, I am a newbie in powershell. I have a simple powershell script that just replace text but I found that the regex replace turn my multiline data source into a single line text when the output is produced. I want the line breaks to be preserved. Here is the dumb down version of the script.
$source=(Get-Content textfile.txt)
$process1 = [regex]::Replace($source, "line", "line2")
$process1 | out-file -encoding ascii textfile2.txt
You can create a test file call textfile.txt with simple lines like this to test it
line
line
Some line
More line here
Have I missed something obvious?
Thanks, Fadrian
© Stack Overflow or respective owner