8000 Get-Content -Delimiter unexpectedly keeps the delimiter in the lines returned · Issue #3706 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Get-Content -Delimiter unexpectedly keeps the delimiter in the lines returned #3706
Closed
@mklement0

Description

@mklement0

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

Metadata

Metadata

Assignees

Labels

Breaking-Changebreaking change that may affect usersIssue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0