Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Get-Content -Delimiter unexpectedly keeps the delimiter in the lines returned #3706

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.