Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PowerShell中跨列添加数字?_Powershell_Calculated Columns - Fatal编程技术网

如何在PowerShell中跨列添加数字?

如何在PowerShell中跨列添加数字?,powershell,calculated-columns,Powershell,Calculated Columns,在我的.csv文件中,我有四列数字,定义如下: aIN=$item1.IN aOUT=$item1.OUT bIN=$item2.IN bOUT=$item2.OUT 数字本身是整数和小数的混合体。我正在尝试使用以下命令查找“总计输入”列和“总计输出”列: IN=aIN+bIN总计 total OUT=aOUT+bOUT 假设我有… aIN aOUT bIN bOUT 0.10.20.30.4 1234 0.50.60.70.8 56778 我想要的是… aIN aOUT bIN bOUT to

在我的.csv文件中,我有四列数字,定义如下:
aIN=$item1.IN

aOUT=$item1.OUT

bIN=$item2.IN

bOUT=$item2.OUT

数字本身是整数和小数的混合体。我正在尝试使用以下命令查找“总计输入”列和“总计输出”列:

IN=aIN+bIN总计

total OUT=aOUT+bOUT

假设我有…
aIN aOUT bIN bOUT

0.10.20.30.4

1234

0.50.60.70.8

56778

我想要的是…
aIN aOUT bIN bOUT total IN total OUT

0.10.20.30.40.40.40.6

123446

0.50.60.70.80.81.21.4

567781214

我的方法行不通。提前感谢您的帮助

使用

  • a
    选择对象
    追加总列
  • 使用ForEach遍历源代码
  • 演替身

您还可以使用
计算属性

$CsvData = @"
aIN,aOUT,bIN,bOUT
0.1,0.2,0.3,0.4
1,2,3,4
0.5,0.6,0.7,0.8
5,6,7,8
"@ | ConvertFrom-Csv | Select-Object *,
    @{n='total-IN';e={[double]$_.aIN  + $_.bIN}},
    @{n='total-OUT';e={[double]$_.aOUT  + $_.bOUT}}

$CsvData | Format-Table -AutoSize
$CsvData | Export-Csv .\your.csv -NoTypeInformation
使用

  • a
    选择对象
    追加总列
  • 使用ForEach遍历源代码
  • 演替身

您还可以使用
计算属性

$CsvData = @"
aIN,aOUT,bIN,bOUT
0.1,0.2,0.3,0.4
1,2,3,4
0.5,0.6,0.7,0.8
5,6,7,8
"@ | ConvertFrom-Csv | Select-Object *,
    @{n='total-IN';e={[double]$_.aIN  + $_.bIN}},
    @{n='total-OUT';e={[double]$_.aOUT  + $_.bOUT}}

$CsvData | Format-Table -AutoSize
$CsvData | Export-Csv .\your.csv -NoTypeInformation

“我的方法不起作用”-什么方法?
total IN=aIN+bIN
total OUT=aOUT+bOUT
“我的方法不起作用”-什么方法?
total IN=aIN+bIN
total OUT=aOUT+bOUT