CSV按标题名称删除列 [英] CSV remove column by header name

查看:106
本文介绍了CSV按标题名称删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个PowerShell脚本,应该删除一个命名列。有没有办法不要选择标题名称xyz的列?

I am working on a little PowerShell script that should remove a named column. Is there a way to not NOT select a column with header name "xyz"?

我尝试通过

$hnames = $csv | Get-Member -MemberType NoteProperty | foreach {$_.name}

并将结果连接到逗号分隔的字符串,

and join the result into a comma separated string and remove the unwanted header

$new = $hnames -join ","
$new = $new -replace "xyz,", ""

并导入/导出CSV select

and import/export the CSV with select

Import-CSV $tempfile -Delimiter ";" | Select $new |
    Export-Csv tempynew.csv -Delimiter ";" -Encoding UTF8 -NoTypeInfo   

但它只输出CSV文件中的标题。

but it only outputs the header in the CSV file.

推荐答案

使用 -ExcludeProperty 参数。 microsoft.com/en-us/library/hh849895.aspxrel =nofollow> Select-Object

Use the -ExcludeProperty parameter with Select-Object instead:

Import-Csv $tempfile -Delimiter ";" | Select * -ExcludeProperty xyz |
    Export-Csv tempynew.csv -Delimiter ";" -Encoding UTF8 -notypeinfo

这篇关于CSV按标题名称删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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