我有一个CSV文件,我需要删除行,这是我的例子
"Name","Local_IP","Remote_IP"
"Sep 1 03:55:57 pc-00017 SymantecServer mserver-4: mmt-5","172.16.48.158","22.22.22.22"
"Sep 1 03:55:57 pc-00017 SymantecServer mserver-4: mmt-5","172.16.48.158","22.22.22.22"
"Sep 1 03:55:57 pc-00017 last message repeated 3 times","","
"Sep 1 03:55:57 pc-00017 SymantecServer mserver-4: mmt-5","172.16.48.158","22.22.22.22"
"Sep 1 03:55:57 pc-00017 last message repeated 2 times","","
"Sep 1 03:55:57 pc-00017 SymantecServer mserver-4: mmt-5","172.16.48.158","22.22.22.22"
我需要删除已删除“最后一条消息重复”的行。
我试过没有运气。
$test = import-csv myfile.csv | where {$_.Name -notcontains "repeated"}
$test | export-csv myfile.csv -notype
有任何帮助吗?
答案 0 :(得分:3)
我觉得这样的事情应该有效:
Get-Content C:\Path\myfile.csv | Where{$_ -notmatch "repeated"} | Out-File C:\Path\myNewFile.csv
答案 1 :(得分:0)
-contains
旨在处理数组,对字符串不太好。按照西尔万的回答Where-Object {$_.Name -notmatch "repeated"}
应该做你想做的事。
有关详细信息,请查看the Technet page。如果没有别的,它告诉你匹配使用正则表达式,以免绊倒这一行。