我有一个包含多个标题的 csv 文档,例如:
"Date","RQ","PM","SME","Activity","Status code" "2/2/12","6886","D_WV","John Smith","Recent","2004"
and a text document that is just a list of status codes, one per line.
I am trying to figure out how to remove all lines from the CSV that contain the status codes from the text file.
So far I have tried using:
$m = gc textfile.txt
Select-String data.csv -Pattern $m -NotMatch
但是,这给我留下了额外的数据,例如
data.csv:1"Date","RQ","PM","SME","Activity","Status code" data.csv:2"2/2/12","6886","D_WV","John Smith","Recent","2004"
I have also tried:
gc data.csv | ? { $_ -notlike $m }
它使用正确的格式,但不想删除任何值。非常感谢任何帮助。
最佳答案
来自 select-string 的那些 matchinfo 对象可能会令人困惑。 这能满足您的需要吗?
$m = gc textfile.txt
select-string data.csv -pattern $m -notmatch |
select -expand line
关于parsing - 从 CSV 中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15579316/