【发布时间】:2017-01-15 14:28:45
【问题描述】:
我在 CSV 文件中有以下数据
"Name","SourceIP","DestinationIP"
"Sep 1 03:55:57 mmt-5","172.16.48.158","22.22.22.22"
"Sep 1 03:55:57 mmt-5","172.16.48.158","22.22.22.22"
"Sep 1 03:55:57 mmt-5","172.16.48.158","22.22.22.22"
"Sep 1 03:55:57 mmt-5","172.16.48.158","22.22.22.22"
我需要将Name 列拆分为另外 3 列。 Date、Time 和 Name。像下面这样
"Date","Time","Name","SourceIP","DestinationIP"
"Sep 1","03:55:57","mmt-5","172.16.48.158","22.22.22.22"
"Sep 1","03:55:57","mmt-5","172.16.48.158","22.22.22.22"
"Sep 1","03:55:57","mmt-5","172.16.48.158","22.22.22.22"
"Sep 1","03:55:57","mmt-5","172.16.48.158","22.22.22.22"
对如何完成有点迷茫。我试过用逗号替换第 14 个字符,但没有运气。
$test = import-csv C-sample.csv
$test | foreach-object {
$_.Name = $_.Name.Replace(14, ",")
}
$test | export-csv D-sample.csv -notype
有什么帮助吗?
【问题讨论】:
标签: regex string powershell csv powershell-2.0