This topic contains 3 replies, has 3 voices, and was last updated by
April 21, 2014 at 2:11 am #14659ParticipantPoints: 0Rank: 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.
April 21, 2014 at 6:37 am #14662KeymasterPoints: 1,704Rank: 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.
April 21, 2014 at 3:56 pm #14681ParticipantPoints: 0Rank: 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:
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
Import-Csv -Delimiter "|" .\data.csv
April 21, 2014 at 5:54 pm #14683ParticipantPoints: 0Rank: 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.