parsing - 从 CSV 中删除行

标签 parsing powershell csv

我有一个包含多个标题的 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/

相关文章:

java - 您将如何提高此正则表达式的效率

java - Android - logInWithReadPermissionsInBackground 上的 NullPointerException

html - 渲染后突出显示页面上的文本

powershell - Invoke-Command 行为澄清

php - 操作/格式化数据库输出

sql - 将文本解析为多列

windows - 获取有关 Windows 计划任务持续时间(执行时间)的信息

node.js - 如何从 gulp 调用执行 PowerShell 脚本?

javascript - 如何使用来自 CSV 的数据将分钟设置为 Highstock 图表中的单位

php - CSV 输出显示整个 HTML 页面