Author Posts

April 21, 2014 at 2:11 am

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.

April 21, 2014 at 6:37 am

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.

April 21, 2014 at 3:56 pm

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:

data.csv:

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

script:

Import-Csv -Delimiter "|" .\data.csv

April 21, 2014 at 5:54 pm

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.