【发布时间】:2017-04-04 03:12:36
【问题描述】:
我需要在许多 csv 文件中将"-" 替换为""(什么都没有),除了Name 列,它可能包含我需要保留的- 字符。
例如:
"Name","timestamp","CPU|Demand (%)","CPU|Demand (%)(趋势)","CPU|Demand (%)(30 天预测)" "ZY02-LAB-WinMachine","2017 年 3 月 2 日 12:01:19 AM","-","38.07","-" "ZY02-LAB-WinMachine","2017 年 3 月 21 日 10:45:00 AM","40.55","-","-" "ZY02-LAB-WinMachine","2017 年 4 月 6 日上午 11:56:19","-","-","38.69" "ZY02-LAB-WinMachine","2017 年 4 月 6 日 12:11:19 PM","-","-","38.7"会变成
"Name","timestamp","CPU|Demand (%)","CPU|Demand (%)(趋势)","CPU|Demand (%)(30 天预测)" "ZY02-LAB-WinMachine","2017 年 3 月 2 日 12:01:19 AM","","38.07","" "ZY02-LAB-WinMachine","2017 年 3 月 21 日 10:45:00 AM","40.55","","" "ZY02-LAB-WinMachine","2017 年 4 月 6 日 11:56:19 AM","","","38.69" "ZY02-LAB-WinMachine","2017 年 4 月 6 日 12:11:19 PM","","","38.7"我在脚本中的行替换了 csv 中的 ALL - .. 甚至是 Name 列 :-(
(Get-Content $ImportCPUFile) | % {$_ -replace "-"} | out-file -FilePath CSV-cleaned.csv -Fo -En ascii
【问题讨论】:
标签: powershell csv