Unable to Import-CSV with line break

Welcome Forums General PowerShell Q&A Unable to Import-CSV with line break

This topic contains 3 replies, has 3 voices, and was last updated by

4 years, 11 months ago.

  • Author
  • #14659

    Points: 0
    Rank: Member

    thing like this, i would like to import text file data into access. The data content example like this: (example.txt)

    ID | Name | Message | User
    1 | Joe | This is a text, error message | admin
    2 | Mary | No error message, ID number: 9182734 | normal-user
    3 | Terry | This is a long text, long message. Product ID : 1234,
    Tag ID : fhdj123, Please restart | admin

    I use -Delimiter "|" as a separator, and it works well for ID 1 and ID 2, but when comes to ID 3, it will just read until "...product ID :1234," then stop. After then, it start read new line from "Tag ID". As you guys can see the "|" is not close at end of ID 3. I wonder how to read string with line break. Please help.

  • #14662

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    The CSV format (regardless of delimiter) defines a line break as an end-of-line. I'm not sure you'll be able to get Import-CSV to do this. You may end up coding your own Import-CSV replacement for this.

  • #14681

    Points: 0
    Rank: Member

    Your file is not "valid" csv (if you can really say "valid" for a semi-standardized format like csv). Generally when a column spans multiple lines, or needs to contain the separator character within the column text, the whole column data should be within quotation characters. If the text should contain a qoutation character, that qoutation character should be doubled.

    The following works fine on my computer running Win8.1 Update with PowerShell 4:


    1|Joe|This is a text, error message|admin
    2|Mary|No error message, ID number: 9182734|normal-user
    3|Terry|"This is a long text, long message. Product ID : 1234,
    Tag ID : fhdj123, Please restart"|admin


    Import-Csv -Delimiter "|" .\data.csv
    • #14683

      Points: 0
      Rank: Member

      Thanks Robert, I see how you solve this problem, it just add a double quotation between the line break Message and it solve my problem too.

      It is a great forum i visited. By the way Don, I am your fans as well. Haha.

The topic ‘Unable to Import-CSV with line break’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort