Read Csv with spaces

20/03/2014 14:04

When we Export list from Sharepoint, get owssrv file and save it as excel file, we can use it as import source for powershell in csv format.

But if some items starts with space, this space is ignored when reading csv file. If we want to find an item by this value, we have to change little csv file as follows (we need to surround text with "" to consider spaces at the beginning or end)


original:

 some name exported  , blue gordon ,


target

" some name exported ","blue gordon ",""


In case of big files use following regex replacements

1. Replace ^ with "

2. Replace , with ","

3. Replace \r\n with "\r\n