[英]Powershell how to add data in the csv file to one column
I have a csv file where is few column. 我有一个csv文件,其中几列。 example
例
col1;col2;col3;col4 COL1; COL2; COL3; COL4
text1;text2;text3;text4 文本1; text2的;文字3;文本4
text5;text6;text7;text8 text5; text6; text7; text8
text9;text10;text11;text12 text9; text10; text11; text12
and I want to add text to column col3, like 我想将文本添加到col3列,例如
col1;col2;col3;col4 COL1; COL2; COL3; COL4
text1;text2;append\\text3;text4 文本1;文本2;附加\\文字3;文本4
text5;text6;append\\text7;text8 text5; text6;追加\\ text7; text8
text9;text10;append\\text11;text12 text9; text10;追加\\ text11; text12
So question is how to do this :) I'm stuck whit that how I add data to each column in col3. 所以问题是如何做到这一点:)我被困在如何向col3中的每一列添加数据。
Give this a whirl: 旋转一下:
Import-Csv -Delim ';' cols.csv |
ForEach-Object {$_.col3 = "prepend\$($_.col3)";$_} |
Export-Csv cols2.csv -Delim ';' -NoTypeInformation
Use the -NoTypeInformation
parameter to avoid this comment getting put at the top of your CSV: 使用
-NoTypeInformation
参数可以避免将此注释放在CSV的顶部:
#TYPE System.Management.Automation.PSCustomObject
However, if you don't mind the comment then you can leave off the -NoTypeInformation
parameter. 但是,如果您不介意注释,则可以不使用
-NoTypeInformation
参数。
You probably know how to read/write data. 您可能知道如何读取/写入数据。 To change the data, send them to
Foreach-Object
, alter the data and pass the object further to Export-Csv
. 要更改数据,请将它们发送到
Foreach-Object
,更改数据,然后将对象进一步传递给Export-Csv
。
Import-Csv d:\temp\so\csv1.txt -Delimiter ';' |
ForEach-Object { $_.col3 = 'append\' +$_.col3; $_ } |
Export-Csv d:\temp\so\csv2.txt -Delimiter ';'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.