.csv carriage return problem

by rob.irvin at 2012-10-10 16:34:54

Hi. I am working with .csv files and am not getting the desired result. I have the following:

$Remote = import-csv -Path "c:\wcsv\remote.csv"
$Local = import-csv -Path "C:\wcsv\local.csv"
$diff = compare-Object $Local $Remote -Property name,slot

The problem is, I am using the $diff array side indicators in a foreach loop. When I look at the output of $diff I can see extra side indicators that I discovered are carriage returns in one of the .csv files. I can remove the carriage returns manually before importing the .csv files and everything is great. However, I am not the one who is creating the .csv files and can’t control whether or not they create them properly. If possible I would like to omit the carriage return blank lines before importing the .csv files into the arrays.
Any help is appreciated and thanks in advance.

Rob
by JeffH at 2012-10-10 18:51:37
So the CSV files have blank lines in them? If so you could try this:

$remote = get-content c:\wcsv\remote.csv | where {$_} | convertfrom-csv
by rob.irvin at 2012-10-10 19:35:36
Thanks Jeff. I’ll be looking at this again tomorrow but after reading about "convertfrom-csv" I think you might have nailed it. Thanks for your quick reply and I’ll let you know how it goes.
by rob.irvin at 2012-10-11 12:59:13
Thanks Jeff… works perfectly.