Description
Note: It may be too late to change this behavior, or perhaps it falls into Bucket 3: Unlikely Grey Area.
If the former, perhaps a -TrimDelimiter
option could be added.
By default, Get-Content
strips the newline character [sequence] from the lines it returns.
The generalization of this concept is to use the -Delimiter
parameter, which allows specifying a custom line (record) delimiter (terminator / separator).
However, unlike with the default delimiter - a newline - whatever -Delimiter
argument you specify is kept in the lines returned, which is:
-
an inconsistency
-
an inconvenience, because the delimiter - which by its nature is not part of the data itself - must be stripped explicitly before further processing.
Steps to reproduce
I'd expect the following 2 commands to be equivalent:
1,2 > t.txt; get-content t.txt | % { "[$_]" }
1,2 > t.txt; get-content -delimiter ([environment]::newline) t.txt | % { "[$_]" }
Expected behavior
[1]
[2]
[1]
[2]
Actual behavior
[1]
[2]
[1
]
[2
]
Note how the trailing newlines were retained in the output from the 2nd command.
Environment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on macOS 10.12.4