本文介绍了Powershell脚本从CSV中删除双引号,除非双引号内存在逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下文件格式的.csv:
I have a .csv in the following file format:
In: "bob","1234 Main St, New York, NY","cool guy"
我要删除没有逗号的双引号:
I am looking to remove double quotes that don't have a comma inside:
Out: bob,"1234 Main St, New York, Ny",cool guy
在Powershell中可以做到这一点吗?
Is there a way to do this in Powershell?
我已检查:
- 如何使用Powershell脚本从CSV文件中删除特定列上的双引号
- http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/02/remove-unwanted-quotation-marks-from-csv-files-by-using-powershell .aspx
- https://social.technet.microsoft.com/Forums/windowsserver/zh-CN/f6b610b6-bfb2-4140-9529-e61ad30b8927/how-to-export-csv-without -doublequote?forum = winserverpowershell
- How to remove double quotes on specific column from CSV file using Powershell script
- http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/02/remove-unwanted-quotation-marks-from-csv-files-by-using-powershell.aspx
- https://social.technet.microsoft.com/Forums/windowsserver/en-US/f6b610b6-bfb2-4140-9529-e61ad30b8927/how-to-export-csv-without-doublequote?forum=winserverpowershell
推荐答案
从:
$csv = 'C:\path\to\your.csv'
(Get-Content $csv) -replace '(?m)"([^,]*?)"(?=,|$)', '$1' |
Set-Content $csv
这篇关于Powershell脚本从CSV中删除双引号,除非双引号内存在逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!