New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parameter -Delimiter to Set-Content, Out-File, Out-String to complement Get-Content -Delimiter #3855
Comments
@iSazonov
It is required options to reproduce this in PowerShell for Windows:
like: "a","b","c" | Out-File text.txt -Encoding utf8NoBOM -Delimiter " " -FinalNewLine "`n"
# equals to
"a", "b", "c" -join " " | Out-File text.txt -Encoding utf8NoBOM -Delimiter "`n" |
Setting a newline option is only really applicable for the writing cmdlets rather than the reading ones, but yeah. I'm wondering if we should have a base class implement the So it would look something like this:
This will involve a bit of refactoring, but it will avoid quite a bit of duplication of code. Some of the base classes may also end up adding methods for stitching the text together, if needed. |
The |
This issue has been marked as won't fix and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
@SteveL-MSFT
Could you tell me how you feel about it? |
I found a good solution to this; hopefully it helps you and others @tats-u Set $Global:PSDefaultParameterValues["Out-File:Encoding"] = "utf8"
$Global:PSDefaultParameterValues['Out-File:NoNewLine'] = $true The |
@ShivnarenSrinivasan This fixes just the half of the issues. This just allows us to use the operator |
@SteveL-MSFT Please reconsider, the To not make this feature a duplicate of |
Additional three arguments why the ugly
|
No way this is still a discussion. Ran into this when pwsh creates CRLF files when creating git patches Ideally there would also be a PSDefaultParameterValues option to set this across the board. |
Is there any process to appeal a decision of some guy at MSFT closing an issue just because they don't see it as a problem themselves? I would like to create a PR myself, but don't want to waste time if it is to be immediately rejected due to the issue being closed. |
@dkaszews Did you ever open a PR for this? I've ran into this issue quite a lot, and would really like some way to change it globally. |
@brian6932 Nope, I lost all motivation for working on PowerShell due to the way mods handle things around here. I have a PR fixing white-on-white text in |
@brian6932 |
By Who? Why? Has this been sufficiently addressed? |
Get-Content -Delimiter
can be used to read text records with an arbitrary (literally matching) terminator into an array of strings, as an alternative to reading line by line.To complement this functionality, the general-purpose text-outputting cmdlets should support the same parameter for creating such files:
Set-Content
/Add-Content
Out-File
Out-String
(
ConvertTo-Csv
andExport-Csv
already have a-Delimiter
parameter, but there it is a field separator (line-internal), and a newline is implied as the record separator.)Note:
-Delimiter ''
would effectively behave the same way as-NoNewline
(which is currently missing fromOut-String
- see Out-String cmdlet should support -NoNewline too #3684).-Delimiter "`n"
on Windows and-Delimiter "`r`n"
on Unix would then allow creating text files with the respective other platform's newline sequence on demand - which would also cover Let us specify EOL when using out-file #2145.The term delimiter is problematic and already ambiguous in terms of what is currently implemented:
In the context of
*-Csv*
cmdlets,-Delimiter
refers to a separator - something placed between elements (fields), but not after the last.In the context of
Get-Content
,-Delimiter
refers to an (optional) terminator, something (expected to be placed after every element (record), including the last.Get-Content -Delimiter
treats input that differs only with respect to a trailing delimiter identically - to signal an empty trailing element two trailing delimiters are needed.This
Get-Content -Delimiter
behavior implies thatSet-Content
,Out-File
, ... should also treat-Delimiter
to mean terminator, and add a trailing delimiter instance to the last record.Desired behavior
Environment Data
The text was updated successfully, but these errors were encountered: