"b`nc" | out-file "a.txt"
output is:
bc
What is the correct way to write a string containing a newline character.
THanks
"b`nc" | out-file "a.txt"
output is:
bc
What is the correct way to write a string containing a newline character.
THanks
Windows system use carriage return + endline (\r\n) like this :
"b`r`nc" | out-file "c:\temp\a.txt"
if you want Something which work on multi-plateform try this:
'b' + [environment]::NewLine + 'c' | out-file "c:\temp\a.txt"
You will occasionally need to use a 'carriage return' in conjunction with newline to get a new line to appear. Try this:
"b`r`nc" | out-file "a.txt"
For more information on carriage returns, you can read this on Stack Overflow.
If you open with Notepad++, you'll see the line break. Also, if you run
Get-Content a.txt
You'll see the line break there too.
Issue here is encoding. For this to work:
"b`nc" | out-file a.txt -Encoding ascii
That should open properly in notepad.