Powershell过滤器csv [英] powershell filter csv

查看:99
本文介绍了Powershell过滤器csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Powershell新手,正在寻求最佳实践方面的帮助,

Looking for help on best practice as I am Powershell newbie,

我有一个csv文件,我想过滤出csv中的每一行,但包含未安装"的行除外

I have a csv file and I would like to filter out every row in the csv except for the rows containing "Not Installed"

然后,我想针对包含计算机列表的单独的csv文件过滤这些结果,并且还排除任何包含匹配项的行.

I would then like to filter those results against a separate csv files housing a list of computers and also exclude any rows containing a match.

任何帮助或起点将不胜感激!

Any help or starting points would be appreciated !

推荐答案

对于第一部分,您可以使用Select-String -Notmatch ...例如:

For the first part, you can use Select-String -Notmatch ... e.g.:

$file = "data.csv"
$csv = Get-Content $file
$csv | Select-String -Notmatch 'Not Installed' | Out-File $file -Enc ascii

如果您的CSV文件恰好是Unicode,则应删除"-Enc ascii"部分,因为输出文件的默认值为Unicode.至于问题的第二部分,您将需要更加具体.但是,您应该查看有关Import-Csv和Export-Csv的帮助:

If your CSV file happens to be Unicode, then remove the "-Enc ascii" part since the default for Out-File is Unicode. As for the second part of your question, you're going to need to be bit more specific. However, you should look at the help on Import-Csv and Export-Csv:

man Import-Csv -full
man Export-Csv -full

这篇关于Powershell过滤器csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆