从CSV中删除线 [英] Removing lines from a CSV
本文介绍了从CSV中删除线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个csv文档,其中包含多个标题:
I have a csv document with multiple headers like:
"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.
我试图找出如何从包含来自文本文件的状态代码的CSV。
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
$ b然而,这留给我额外的数据,如
However that leaves me with extra data such as
data.csv:1"Date","RQ","PM","SME","Activity","Status code"
data.csv:2"2/2/12","6886","D_WV","John Smith","Recent","2004"
我也尝试过:
gc data.csv | ? { $_ -notlike $m }
使用正确的格式,但不想删除任何价值。任何帮助是非常感谢。
That uses the proper formatting but does not want to remove any of the values. Any help is much appreciated.
推荐答案
来自select-string的matchinfo对象可能会让人困惑。
这需要什么?
Those matchinfo objects from select-string can be confusing. Does this do what you need?
$m = gc textfile.txt
select-string data.csv -pattern $m -notmatch |
select -expand line
这篇关于从CSV中删除线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文