我有以下文件格式的.csv:
In: "bob","1234 Main St,New York,NY","cool guy"
我想删除里面没有逗号的双引号:
Out: bob,Ny",cool guy
有没有办法在Powershell中做到这一点?
我检查过:
> 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
调整
“How to remove double quotes on specific column from CSV file using Powershell script”的代码:
$csv = 'C:\path\to\your.csv' (Get-Content $csv) -replace '(?m)"([^,]*?)"(?=,|$)','$1' | Set-Content $csv
正则表达式(?m)“([^,] *?)”(?=,| $)匹配逗号或行尾之前的任何“0或更多非逗号”(以正面预测和多线选项(?m)强制$匹配换行符,而不仅仅是字符串的结尾.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。