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

ConvertTo-Csv / Export-Csv do not create valid CSV with new-lines and double-quotes #9284

Copy link
Copy link
@jsnape

Description

@jsnape
Issue body actions

Steps to reproduce

Using the following as a test (this is valid CSV).

label,testvalue
"blank",""
"null",
"comma","the quick, brown, fox"
"single-quote","the quick 'brown' fox"
"double-quote","the quick ""brown"" fox"
"newline","the quick brown
     fox"
"newline after double-quote","the quick ""brown""
     fox"
"newline before double-quote","the quick ""brown
    "" fox"
"double-quote comma newline","the quick ""brown"",
     fox"
PS> (gc test.csv | convertFrom-csv) | Export-csv -Path test2.csv -NoTypeInformation
# or
PS> (gc test.csv | convertFrom-csv) | ConvertTo-Csv -NoTypeInformation | Out-File -Path test2.csv -NoTypeInformation

Expected behavior

The output file should look the same as the input file

Actual behavior

Its OK that there are quotes around everything now but the formatter has closed the double-quote before the line break and as a result introduced new records into the file.

"label","testvalue"
"blank",""
"null",
"comma","the quick, brown, fox"
"single-quote","the quick 'brown' fox"
"double-quote","the quick ""brown"" fox"
"newline","the quick brown"
"fox""",
"newline after double-quote","the quick ""brown"""
"fox""",
"newline before double-quote","the quick ""brown"
" fox""",
"double-quote comma newline","the quick ""brown"","
"fox""",

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.316
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.316
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-AnsweredThe question is answered.The question is answered.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module

    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.