Question:
When running the following code:
1 2 3 4 5 6 7 8 9 10 |
$txt = Get-Content file1.txt $a = @" -- file start -- $txt -- file end -- "@ $a |
All new lines are removed from the file’s contents, but just running
1 2 |
$txt |
prints out the file without stripping the new lines.
Any idea how to get it to work as desired using the here-string?
Thanks!
Answer:
Pipe $txt to Out-String inside a sub-expression.
1 2 3 4 5 6 |
$a = @" -- file start -- $($txt | Out-String) -- file end -- "@ |