将列添加到CSV Windows PowerShell [英] Add Column to CSV Windows PowerShell
本文介绍了将列添加到CSV Windows PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个相当标准的csv文件与标题我想添加一个新的列&
I have a fairly standard csv file with headers I want to add a new column & set all the rows to the same data.
column1, column2
1,b
2,c
3,5
之后
After
column1, column2, column3
1,b, setvalue
2,c, setvalue
3,5, setvalue
如果有人可以指向正确的方向,将是伟大的。
I can't find anything on this if anybody could point me in the right direction that would be great. Sorry very new to Power Shell.
推荐答案
这里有一种使用计算属性的方法:
Here's one way to do that using Calculated Properties:
Import-Csv file.csv |
Select-Object *,@{Name='column3';Expression={'setvalue'}} |
Export-Csv file.csv -NoTypeInformation
http://technet.microsoft.com/en-us/library/ff730948.aspx 。
简而言之,您导入文件,将内容传递到 Select-Object
cmdlet,属性(例如'*'),然后添加一个新的。
In a nutshell, you import the file, pipe the content to the Select-Object
cmdlet, select all exiting properties (e.g '*') then add a new one.
这篇关于将列添加到CSV Windows PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文