Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

How to import-csv file with double quotes in the data

$
0
0

Hi,

Scenario:

Via PowerShell, I export the follwoing two column 'csv' file.  Note, the 'description' column can contain any rich html syntax (<div>, class="some-name", qouble/single quotes, carriage returnd, end of line, etc.):

Name|description
"John Carter"|"PowerShell maps this whole text to the description column."
"Bob Segel"| "PowerShell would only map the text "before" this double quote."

In PowerShell, i run the follwoing command:

Import-csv -Path "c:\\sample-input.csv" -Delimiter "|"

I understand that, while reading column value, PowerShell would treat double quotes as the end of string.  But I need to find a way to map all of the text (including quotes and post double quotes) to the column 'description'.

Undersired Solution::
. While exporting, I do not want to manipulate the description data, like replace double quotes with single quote.  I need to keep the original formating intact.

Desired Solution::
. While exporting, is there a way to use 'here-string' (@) like symbol that can be inserted infront of the text for the 'descrition' column.  So while importing, PowerShell treats all the text in the 'description' column as a single string (including the quotes); thus reading all the text?
. Any other out of the box PowerShell functionality that i can leverage?

Solution I am thinking of::

Until I find a better alternative, I am thinking to export all the data as XML and use 'CDATA' to export the values for the 'description' column.

thank you for your time and help.









Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>