Unable to Import-CSV with line break

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.

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.

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

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.