Windows Powershell 重命名列标题 CSV 文件 [英] Windows Powershell Rename Column Heading CSV file
问题描述
很抱歉发布此消息,但我无法弄清楚如何使用 Windows PowerShell 重命名 csv 文件中的列标题这样的基本操作.我可以添加、删除、填充、导出,但不知道如何更改标题.
Apologies for posting this but I cannot work out how to do such a basic thing as to rename a column heading in a csv file with windows powershell. I can add new, delete, fill, export but cannot find out how to change a heading.
我想也许可以导入 CSV &使用指定的标头导出但不起作用:
I thought maybe import the CSV & export with header specified but doesn't work:
import-csv c:\tmp\test.csv | Select-Object first_name | Export-Csv -header "test" c:\tmp\test1.csv
我基本上需要重新格式化一个 CSV 文件,所以如果我可以选择我想要的数据 &指定完美的新标题.
I basically need to re-format a CSV file so if I can select the data I want & specify the new headers that would be perfect.
当然,这应该是直截了当的,我一定遗漏了一些明显的东西......
Surely this should be straight forward I must be missing something obvious....
推荐答案
您可以使用 Select-Object
和 计算属性来做到这一点.
You may use Select-Object
with a calculated property to do this.
Import-Csv test.csv |
Select-Object @{ expression={$_.first_name}; label='test' } |
Export-Csv -NoTypeInformation test1.csv
这篇关于Windows Powershell 重命名列标题 CSV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!