Update:
Thanks to Keith-Miller's suggestion below, I was able to use StreamReader.ReadBlock()
to pull out a block of characters, then search through that string for the last row delimiter using String.LastIndexOf()
. Fortunately in this case, the row delimiter was `r`n
, while the line breaks in the cell were only `r
. I'm still not at a final solution for this file because of another issue, but I will provide another update once I've found it!
Original post:
Suppose I have a CSV that looks like this:
ID | Message
-----+------------------
1 | Buy milk
2 | Don't forget
| to eat
| candy
3 | Also pizza
or, as it would be saved in the text file:
ID,Message
1,"Buy milk"
2,"Don't forget
to eat
candy"
3,"Also pizza"
How could I import the records for ID 1 and 2 without the record for ID 3?
Get-Content -Head
would require knowledge of how many line breaks are in each row.StreamReader
would return rows liketo eat
, once again needing knowledge of the line breaks in each row.- Stripping the line breaks from the file would also strip the line breaks from the end of the line, resulting in a one-row, many-column table.
For additional context, I'm trying to import this CSV in chunks because it is so large, so if there is a read-line-by-line (or even many-lines-at-a-time) solution, I would really appreciate it. As opposed to "Import the huge CSV and then pull out the rows you need."