You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-Content -Delimiter unexpectedly keeps the delimiter in the lines returned #3706
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.
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:
Just wondering if this could be tied up with this other issue experiencing with Import-Csv:
"Import-Csv does not handle newlines containing just \r (Carriage Return) #3692"
Maximo Trinidad (@MaximoTrinidad): The other issue is somewhat related, though in the case of Import-Csv the proper fix is to have it accept \r-only line breaks too (in line with Get-Content), so I see less of a need for an explicit -Delimiter parameter there.
I agree that both should work uniformly Get-Content and Get-Content -Delimiter. Although the parameter name LineTerminator is more suitable.
And it is an other issue - Import-Csv don't use FileProvider code. Although worth discussing that all file cmdlets (Out-File, Import-Csv, Export-Csv ...) have been based on FileProvider code to work uniformly.
Historically, there's been a lot of confusion around the terms separator, delimiter, and terminator.
I agree that -Delimiter is not a great name, and that terminator is more appropriate here - though, arguably, we're then not dealing with lines anymore, but with the abstraction of records (the terminology adopted by awk for instance, which has otherwise settled on separator, unfortunately).
Therefore, bypassing the secondary issue of line vs. record, perhaps defining -Terminator as an alias for -Delimiter is appropriate (-Delimiter currently has no alias).
In the context of CSV files, specifically, which are line-oriented, line terminator is the right term.
By contrast, by allowing arbitrary terminator strings with -Delimiter, what a terminator terminates is no longer necessarily a line: with a terminator other than a newline (in any of its variations), any number of lines may then occur between instances of the terminator.
In other words: the units of data may themselves be multi-line, so calling such a unit a line is inappropriate.
That's why awk chose record, for instance, but my point is that it isn't necessary for the parameter name to reflect a term for the data unit, given that only one kind of terminator is supported (for the implied lines / data units).
On a meta note: even though the label of your link suggests that it is to a specific comment on the issue page, the link is just to the issue page itself.
A recent post by Jason Shirk (@lzybkr) exhibited the same problem.
How are you generating these links? Is this a GitHub bug?
Shrey Jain (@shreyjain362), it has been fixed in PowerShell 7 (which this repo is solely devoted to) - at least judging by running the original reproduction steps.
Note that Windows PowerShell won't receive this fix, because it is no longer actively developed and only receives security-critical fixes.
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.
Activity
MaximoTrinidad commentedon May 5, 2017
Hey Ilya (@iSazonov),
Just wondering if this could be tied up with this other issue experiencing with Import-Csv:
"Import-Csv does not handle newlines containing just \r (Carriage Return) #3692"
Can someone confirmed this?
:)
mklement0 commentedon May 5, 2017
Maximo Trinidad (@MaximoTrinidad): The other issue is somewhat related, though in the case of
Import-Csvthe proper fix is to have it accept\r-only line breaks too (in line withGet-Content), so I see less of a need for an explicit-Delimiterparameter there.MaximoTrinidad commentedon May 5, 2017
Thanks Michael Klement (@mklement0)!
iSazonov commentedon May 5, 2017
I agree that both should work uniformly
Get-ContentandGet-Content -Delimiter. Although the parameter nameLineTerminatoris more suitable.And it is an other issue -
Import-Csvdon't use FileProvider code. Although worth discussing that all file cmdlets (Out-File, Import-Csv, Export-Csv ...) have been based on FileProvider code to work uniformly./cc jeffbi
mklement0 commentedon May 9, 2017
Ilya (@iSazonov):
Historically, there's been a lot of confusion around the terms separator, delimiter, and terminator.
I agree that
-Delimiteris not a great name, and that terminator is more appropriate here - though, arguably, we're then not dealing with lines anymore, but with the abstraction of records (the terminology adopted byawkfor instance, which has otherwise settled on separator, unfortunately).Therefore, bypassing the secondary issue of line vs. record, perhaps defining
-Terminatoras an alias for-Delimiteris appropriate (-Delimitercurrently has no alias).iSazonov commentedon May 10, 2017
Michael Klement (@mklement0) We could rely on the W3C standard - Model for Tabular Data and Metadata on the Web
line terminators (from #3692 (comment))
mklement0 commentedon May 11, 2017
Ilya (@iSazonov):
In the context of CSV files, specifically, which are line-oriented, line terminator is the right term.
By contrast, by allowing arbitrary terminator strings with
-Delimiter, what a terminator terminates is no longer necessarily a line: with a terminator other than a newline (in any of its variations), any number of lines may then occur between instances of the terminator.In other words: the units of data may themselves be multi-line, so calling such a unit a line is inappropriate.
That's why
awkchose record, for instance, but my point is that it isn't necessary for the parameter name to reflect a term for the data unit, given that only one kind of terminator is supported (for the implied lines / data units).On a meta note: even though the label of your link suggests that it is to a specific comment on the issue page, the link is just to the issue page itself.
A recent post by Jason Shirk (@lzybkr) exhibited the same problem.
How are you generating these links? Is this a GitHub bug?
iSazonov commentedon May 11, 2017
Michael Klement (@mklement0) You can copy such links from post header datetime string "mklement0 commented 9 minutes ago".
It is GitHub bug.
Fix for Get-Content -Delimiter including the delimiter in the array e…
Fix for Get-Content -Delimiter including the delimiter in the array e…
shreyjain362 commentedon Jun 17, 2024
The issue is still not resolved. Why has it been marked "Resolution Fixed"? Michael Klement (@mklement0) Ilya (@iSazonov)
mklement0 commentedon Jun 17, 2024
Shrey Jain (@shreyjain362), it has been fixed in PowerShell 7 (which this repo is solely devoted to) - at least judging by running the original reproduction steps.
Note that Windows PowerShell won't receive this fix, because it is no longer actively developed and only receives security-critical fixes.
Fix for Get-Content -Delimiter including the delimiter in the array e…
Fix for Get-Content -Delimiter including the delimiter in the array e…