Powershell script to remove double quotes from CSV unless comma exists inside double quotes

Question:

I have a .csv in the following file format:

I am looking to remove double quotes that don’t have a comma inside:

Is there a way to do this in Powershell?

I have checked:

  1. How to remove double quotes on specific column from CSV file using Powershell script
  2. http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/02/remove-unwanted-quotation-marks-from-csv-files-by-using-powershell.aspx
  3. https://social.technet.microsoft.com/Forums/windowsserver/en-US/f6b610b6-bfb2-4140-9529-e61ad30b8927/how-to-export-csv-without-doublequote?forum=winserverpowershell

Answer:

Adapting the code from “How to remove double quotes on specific column from CSV file using Powershell script”:

The regex (?m)"([^,]*?)"(?=,|$) is matching any " + 0 or more non-commas + " before a comma or end of line (achieved with a positive look-ahead and a multiline option (?m) that forces $ to match a newline, not just the end of string).

See regex demo

Source:

Powershell script to remove double quotes from CSV unless comma exists inside double quotes by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply